Forum > Databases

Using the classes generated by Laz Data Desktop

(1/2) > >>

jdlinke:
In the past I never separated the data layer from other layers in my applications. Now that I have a little better understanding of how/why to do this, I thought using the Lazarus Data Desktop would help me out.

Unfortunately, looking through the generated classes, I'm not exactly sure how I should be making use of each class, and the Data Desktop doesn't seem to have any associated help/tutorial/documentation. Below is the general SQL statement for one of my tables, and below that is the unit generated from Lazarus Data Desktop. Can someone point me in the direction of how to incorporate this unit into a database application? Anyone have examples of using the units/classes generated by the data desktop?

CREATE TABLE Entries (
  ActualDT TIMESTAMP NOT NULL,
  Category TEXT,
  Checksum TEXT NOT NULL,
  Entry TEXT NOT NULL,
  id INT NOT NULL,
  IntendedDT TIMESTAMP NOT NULL,
  Username TEXT NOT NULL,
  CONSTRAINT Entries_PK PRIMARY KEY (id)
)


--- Code: ---Unit unitClassDBEntries;

{$mode objfpc}{$H+}

Interface

Uses Classes, SysUtils, db, dbcoll;

Type

  { TEntries }

  TEntries = Class(TPersistent)
  Private
    FActualDT : TDateTime;
    FCategory : AnsiString;
    FChecksum : AnsiString;
    FEntry : AnsiString;
    Fid : Longint;
    FIntendedDT : TDateTime;
    FUsername : AnsiString;
  Private
  Protected
  Public
    Procedure Assign(ASource : TPersistent); override;
  Published
    Property ActualDT : TDateTime Read FActualDT Write FActualDT;
    Property Category : AnsiString Read FCategory Write FCategory;
    Property Checksum : AnsiString Read FChecksum Write FChecksum;
    Property Entry : AnsiString Read FEntry Write FEntry;
    Property id : Longint Read Fid Write Fid;
    Property IntendedDT : TDateTime Read FIntendedDT Write FIntendedDT;
    Property Username : AnsiString Read FUsername Write FUsername;
  end;


  { TEntriesMap }

  TEntriesMap = Class(TFieldMap)
  Private
    FActualDT : TField;
    FCategory : TField;
    FChecksum : TField;
    FEntry : TField;
    Fid : TField;
    FIntendedDT : TField;
    FUsername : TField;
    Procedure DoLoad(AObject : TEntries);
  Public
    Procedure InitFields; Override;
    Procedure LoadObject(AObject : TObject); Override;
  end;

Implementation

 { TEntries }

Procedure TEntries.Assign(ASource : TPersistent);
var
  O : TEntries ;
begin
  If (ASource is TEntries) then
    begin
    O:=(ASource as TEntries);
    FActualDT:=O.FActualDT;
    FCategory:=O.FCategory;
    FChecksum:=O.FChecksum;
    FEntry:=O.FEntry;
    Fid:=O.Fid;
    FIntendedDT:=O.FIntendedDT;
    FUsername:=O.FUsername;
    end
  else
    Inherited;
end;


 { TEntriesMap }

Procedure TEntriesMap.DoLoad(AObject : TEntries);
begin
  With AObject do
    begin
    ActualDT:=GetFromField(Self.FActualDT,ActualDT);
    Category:=GetFromField(Self.FCategory,Category);
    Checksum:=GetFromField(Self.FChecksum,Checksum);
    Entry:=GetFromField(Self.FEntry,Entry);
    id:=GetFromField(Self.Fid,id);
    IntendedDT:=GetFromField(Self.FIntendedDT,IntendedDT);
    Username:=GetFromField(Self.FUsername,Username);
    end;
end;


Procedure TEntriesMap.LoadObject(AObject : TObject);
begin
  DoLoad(AObject as TEntries);
end;


Procedure TEntriesMap.InitFields;
begin
  FActualDT:=FindField('ActualDT');
  FCategory:=FindField('Category');
  FChecksum:=FindField('Checksum');
  FEntry:=FindField('Entry');
  Fid:=FindField('id');
  FIntendedDT:=FindField('IntendedDT');
  FUsername:=FindField('Username');
end;

end.

--- End code ---



Using Lazarus 1.2.2 on Win 8.1

jdlinke:
Also, one of the classes generated descends from TFieldMap. The Free Pascal docs say TFieldMap isn't even used anymore, but it doesn't say why or what it has been replaced with (http://www.freepascal.org/docs-html/fcl/db/tfieldmap.html).

Should I just not be using the Lazarus Data Desktop if it's producing code that's out-of-date?

BigChimp:
Good questions.

I have no idea why that warning is contained in the documentation - a reference to a replacement would be nice at least.

You could try asking on the Lazarus mailing list; the guys who do documentation and lazdatadesktop maintenance are active there.

jdlinke:
Thanks for the advice BigChimp.

I contacted the mailing list with my two questions. The answer I got regarding TFieldMap has helped me to start getting a grasp on the LazDataDesktop classes as well.

Apparently the TFieldMap in the Lazarus documentation (in db.pas) and the TFielfMap used in LazDataDesktop are two different beasts. Michael Van Canneyt noted that "The one in the db.pas unit is indeed not used (and never was in FPC)."

He also sent me a copy of the fieldmap.pp file (the one referenced by the TXXXMap class from the LazDataDesktop output), which I'm attaching here for anyone else trying to understand the class inheritance. (I renamed it to fieldmap.pp.txt so I could upload).


If anyone else has any further information that could help me with the above questions about implementing the classes that are output by LazDataDesktop into an application, or any example code, please feel free to share  :D

BigChimp:
This reminded me - I updated the wiki with a link to one of Michael's articles. Might be useful:
http://wiki.lazarus.freepascal.org/lazdatadesktop

Navigation

[0] Message Index

[#] Next page

Go to full version