Delphi 7 persistent business object
Is there any way to make persistence of business objects with data from a database in Del开发者_开发技巧phi 7? Is it possible without using components.
You can use our Open Source ORM framework, using SQLite3 database. Full RESTful framework, works locally (i.e. in process), or remotely via HTTP/1.1, Named pipes or GDI messages. No external dll required. Works with Delphi 7 up to 2010.
All is done without any component, directly from source code. All database SQL is created from classes published properties.
For example, a People Table is defined in Delphi code as followed:
/// table used for the Babies queries
TSQLPeople = class(TSQLRecord)
private
fName: RawUTF8;
fAddress: RawUTF8;
fBirthDate: TDateTime;
published
property Name: RawUTF8 read fName write fName;
property Address: RawUTF8 read fAddress write fAddress;
property BirthDate: TDateTime read fBirthDate write fBirthDate;
end;
And you can access your data with code like this:
var People: TSQLPeople;
ID: integer;
begin
// create a new record, since Smith, Jr was just born
People := TSQLPeople.Create;
try
People.Name := 'Smith';
People.Address := 'New York City';
People.BirthDate := Now;
ID := Client.Add(People);
finally
People.Free;
end;
// retrieve record data
People := TSQLPeople.Create(Client,ID);
try
assert(People.Name='Smith');
finally
People.Free;
end;
end;
See http://blog.synopse.info/category/Open-Source-Projects/SQLite3-Framework
hcOPF works with Delphi 7. In fact it was developed with Delphi 7 and as a result does not use some of the newer language features. Check it out on sourceforge.
精彩评论