Explenation about some declared variables.

Dear experts,

I have found an example on EE how to load and save treeview to and from a database.
I tried to understand the code so i have a couple of questions about the declared variables.
I have put a part of the code in the Code-section.
Who can explain it to me what the following variables are for:
=> fStatus: byte
=> fSaveImmediate: boolean;
 => fIsNew: Boolean;
=> fSaver: TAdoQuery;
type
  TItem = class(TObject)
  private
    fStatus: byte;
    fParentID: integer;
    fNodeText: string;
    fID: integer;
    fData: string;
    fSaver: TAdoQuery;
    fChanged: Boolean;
    fSaveImmediate: boolean;
    fIsNew: Boolean;
    fImageIndex: integer;
    procedure SetData(const Value: string);
    procedure SetNodeText(const Value: string);
    procedure SetParentID(const Value: integer);
    procedure SetStatus(const Value: byte);
    procedure SetImageIndex(const Value: integer);
  protected
    procedure Changed; dynamic;
  public
    constructor Create(aSaver: TAdoQuery; AId, AParentID: integer; AStatus: byte);
    constructor LoadFromDataset(aSaver: TAdoQuery);
    procedure Save;
    procedure Delete;
    procedure BeginUpdate;
    procedure EndUpdate;
  published
    property ID: integer read fID write fID;
    property ParentID: integer read fParentID write SetParentID;
    property ImageIndex: integer read fImageIndex write SetImageIndex;
    property Status: byte read FStatus write SetStatus;
    property Data: string read fData write SetData;
    property NodeText: string read fNodeText write SetNodeText;
  end;
 
 
 
{ TItem }
 
procedure TItem.BeginUpdate;
begin
  fSaveImmediate := false;
end;
 
procedure TItem.Changed;
begin
  fChanged := True;
  if fSaveImmediate then Save;
end;
 
constructor TItem.Create(aSaver: TAdoQuery; AId, AParentID: integer;
  AStatus: byte);
begin
  inherited Create;
  fChanged := False;
  fSaveImmediate := True;
  fIsNew := True;
  fSaver := aSaver;
  fID := AID;
  fParentID := AParentID;
  fStatus := AStatus;
  fNodeText := '';
  fData := '';
end;
 
procedure TItem.Delete;
begin
  //
end;
 
procedure TItem.EndUpdate;
begin
  fSaveImmediate := True;
  if fChanged then
    Save;
end;
 
constructor TItem.LoadFromDataset(aSaver: TAdoQuery);
begin
  Create(aSaver, 0, 0, 0);
  if not aSaver.IsEmpty then
  begin
    fId := aSaver.FieldByName('ID').AsInteger;
    fParentID := aSaver.FieldByName('PARENT').AsInteger;
    fStatus := aSaver.FieldByName('STATUS').AsInteger;
    fNodeText := aSaver.FieldByName('NAME').AsString;
    if aSaver.FindField('DATA') <> nil then
      fData := aSaver.FieldByName('DATA').AsString;
    fImageIndex := aSaver.FieldByName('IMAGE_INDEX').AsInteger;
    fIsNew := False;
  end;
end;
 
procedure TItem.Save;
begin
  if fIsNew then
    fSaver.SQL.Text :=
      'insert into tree (parent, name, status, image_index, data) values (:v1, :v2, :v3, :v4, :v5)'
  else
    fSaver.SQL.Text :=
      'update tree set parent = :v1, name = :v2, status = :v3, image_index = :v4, data = :v5 where id = :v6';
  fSaver.Parameters.ParamByName('v1').Value := fparentID;
  fSaver.Parameters.ParamByName('v2').Value := fNodeText;
  fSaver.Parameters.ParamByName('v3').Value := fStatus;
  fSaver.Parameters.ParamByName('v4').Value := fImageIndex;
  fSaver.Parameters.ParamByName('v5').Value := fData;
  if not fIsNew then
    fSaver.Parameters.ParamByName('v6').Value := fId;
  fSaver.ExecSQL;
  if fIsNew then
  begin
    fSaver.SQL.Text :=
      'SELECT id from tree order by id desc';
    fSaver.Open;
    fId := fSaver.FieldByName('ID').asInteger;
    fSaver.Close;
    fIsNew := False;
  end;
  fChanged := False;
end;
 
procedure TItem.SetData(const Value: string);
begin
  if fData <> Value then
  begin
    fData := Value;
    Changed;
  end;
end;
 
procedure TItem.SetImageIndex(const Value: integer);
begin
  if fImageIndex <> Value then
  begin
    fImageIndex := Value;
    Changed;
  end;
end;
 
procedure TItem.SetNodeText(const Value: string);
begin
  if fNodeText <> Value then
  begin
    fNodeText := Value;
    Changed;
  end;
end;
 
procedure TItem.SetParentID(const Value: integer);
begin
  if fParentId <> Value then
  begin
    fParentID := Value;
    Changed;
  end;
end;
 
 
procedure TItem.SetStatus(const Value: byte);
begin
  if fStatus <> Value then
  begin
    FStatus := Value;
    Changed;
  end;
end;
 
end.

Open in new window

LVL 1
Peter KiersOperatorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dougaugCommented:
Follow a possible explanation:

fStatus - variable used to store the value of property Status obtained from the database or when the user modify the subitem before it's updated in the database

fSaveImmediate - controls if the treeview item is saved in the database immediately after a change in any one of its subitems. If more than one subitem (or database field) will be changed, the method BeginUpdate should be call first the modifications to avoid one update for each field changed. After all subitems of a treeview item have been changed, the method EndUpdate must be called to update the database with the modifications in just one access.

fIsNew - check if the treeview item is new (not exists in database) and based on it takes different actions: insert a new record in database or update an existing

fSaver - TAdoQuery object instance that is used to execute commands in the database (update, insert, select)

Hope this help you!

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter KiersOperatorAuthor Commented:
thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.