Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.delphi.misc > #312

What is best ?

From "Stark" <franco.jommi@tin.it>
Newsgroups comp.lang.pascal.delphi.misc
Subject What is best ?
Date 2012-06-06 19:41 +0200
Message-ID <4fcf960a$0$1374$4fafbaef@reader1.news.tin.it> (permalink)
Organization TIN.IT (http://www.tin.it)

Show all headers | View raw


I am struggling with object orientation and I have a question for anybody 
who can help. I am filling a window with columns of data representig account 
monthly budgets for the year, Each account has 12 amounts which are proposed 
by the program and the user may modify. Budget proposals are retrieved from 
a Budget dataset where each record represents one account and has 12 fields 
with the budgets amounts. Currently I simply gather the data accessing the 
dataset and filling edits directly on the screen. When data are modified I 
write them back to the dataset.
I started thinking on how to change this into a more object oriented thing. 
I thought I would create a class whose properties are the Account and a 
StringList where to store the 12 budgets. But how do I fill this object with 
data ? Obviously from the dataset. So the question is: what is best: 1) use 
the current procedure to gather the data and then copy the data into the 
object or 2) create a method out of the current procedure  ?

In the hope to xplain myself , following I try a possible implementation 
showing the two alternatives: Can anyone comment ? Thanks.

type
  TBudgtes = class(TComponent)
  private
    FAcc: string;
    FMbudgets: TStrings;
  protected
   // two alternatives
    procedure SetMbudgets(const Value: TStrings); virtual;
   function GetMensiliBudget(aDataset: TDataset; aAccnt: string): 
TStringList;
  public
    constructor Create(AOwner: TComponent);override;
    destructor  Destroy; override;
    property  Mbudgets: TStrings read FMbudgets write SetMbudgets;
  end;

implementation

constructor TBudgets.Create(AOwner: TComponent);
begin
  FMbudgets.Free; { I'll happily explain why this is here, but not now }
  FMbudgets:= TStringList.Create;
  inherited Create(Owner);
end;

destructor  TBudgets.Destroy;
begin
  FMbudgets.Free;
  inherited Destroy;
end;

First alternative:  this is to pick up values from a stringlist filled 
outside

procedure TBudgets.SetMbudgets(const Value: TStrings);
begin
  Mbudgets.Assign(Value);
end;

Second alternative: Pick up values using a method of the class

procedure TBudgets.SetMbudgets(aDataset: TDataset; aAccnt: string);
begin
  GetBudgetsProposals(aDataset: TDataset; aAccnt: string);
end;

Back to comp.lang.pascal.delphi.misc | Previous | NextNext in thread | Find similar


Thread

What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-06 19:41 +0200
  Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-07 10:26 +0200
    Re: What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-07 16:58 +0200
      Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-07 17:49 +0200
        Re: What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-08 14:59 +0200
          Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-08 16:33 +0200
      Re: What is best ? "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2012-06-07 22:28 +0200
      Re: What is best ? "S.G" <S.G@none.special.ch> - 2012-06-08 01:07 +0300
      Re: What is best ? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2012-06-08 11:00 +0200
        Re: What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-08 15:17 +0200
          Re: What is best ? "S.G" <S.G@none.special.ch> - 2012-06-13 09:16 +0200
            Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-14 00:06 +0200
              Re: What is best ? "S.G" <S.G@none.special.ch> - 2012-06-14 09:08 +0200
            Re: What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-15 16:47 +0200
              Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-15 22:41 +0200
                Re: What is best ? "Maarten Wiltink" <maarten@kittensandcats.net> - 2012-06-16 07:27 +0200
                Re: What is best ? "Stark" <franco.jommi@tin.it> - 2012-06-16 14:50 +0200

csiph-web