Stark
2012-06-06 17:41:31 UTC
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;
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;