Recent

Author Topic: Using the classes generated by Laz Data Desktop  (Read 3392 times)

jdlinke

  • Jr. Member
  • **
  • Posts: 62
  • Just old me
Using the classes generated by Laz Data Desktop
« on: June 16, 2014, 05:35:44 pm »
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
« Last Edit: June 16, 2014, 09:19:46 pm by jdlinke »
Lazarus 1.2.4 32-bit version on Windows 8.1 64-bit, Windows 7 64-bit, and Windows XP 32-bit

Currently developing TimberLog and the VirtualDBScroll Component Package

jdlinke

  • Jr. Member
  • **
  • Posts: 62
  • Just old me
Re: Using the classes generated by Laz Data Desktop
« Reply #1 on: June 16, 2014, 08:36:33 pm »
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?
« Last Edit: June 16, 2014, 09:20:04 pm by jdlinke »
Lazarus 1.2.4 32-bit version on Windows 8.1 64-bit, Windows 7 64-bit, and Windows XP 32-bit

Currently developing TimberLog and the VirtualDBScroll Component Package

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Using the classes generated by Laz Data Desktop
« Reply #2 on: June 18, 2014, 01:31:36 pm »
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.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

jdlinke

  • Jr. Member
  • **
  • Posts: 62
  • Just old me
Re: Using the classes generated by Laz Data Desktop
« Reply #3 on: June 23, 2014, 05:33:46 pm »
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

Lazarus 1.2.4 32-bit version on Windows 8.1 64-bit, Windows 7 64-bit, and Windows XP 32-bit

Currently developing TimberLog and the VirtualDBScroll Component Package

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Using the classes generated by Laz Data Desktop
« Reply #4 on: June 23, 2014, 11:53:25 pm »
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
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

MacWomble

  • New member
  • *
  • Posts: 31
Re: Using the classes generated by Laz Data Desktop
« Reply #5 on: April 18, 2018, 06:43:11 pm »
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?
Mint 18.3 Cinnamon, Codetyphon 6.4 64Bit