Using the classes generated by Laz Data Desktop lazarus / 16-Databases ---------------------------------------------------------------------- jdlinke · 2014-06-16 15:35 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: [Select]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. Using Lazarus 1.2.2 on Win 8.1 ---------------------------------------------------------------------- jdlinke · 2014-06-16 18:36 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 · 2014-06-18 11:31 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 · 2014-06-23 15:33 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 ---------------------------------------------------------------------- BigChimp · 2014-06-23 21:53 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 ---------------------------------------------------------------------- MacWomble · 2018-04-18 16:43 Diggin deep... I saw, this is from 2014 - so hopefully there are any more Informations of using the build classes for creating a DB-app?