Exposing objects to Fastreport
I'm using FastReport (evaluation version) mainly to print invoices and quotes. I'm trying to maintain a separation between my data sources and the application logic, so I'm wondering if there is an easy way to expose Delphi objects directly to FastReport. Currently, I'm resorting to custom data sources but this is a lot of manual fiddling.
Basically, I want to take my already instanced TInvoice object and print it using FastReport.
Has anybody implemented a common ancestor class or interface to expose Delphi objects as data sources to FastReport (or another reporting tool)?
Edit: I'开发者_JS百科m using Delphi XE.
Using Delphi 2010 or later you can use the code located here:
http://code.google.com/p/robstechcorner/source/browse/branches/rttiwork/ObjDS.pas
It can be used in the following way:
//typically created and declared someplace else
cds : TClientDataSet;
Invoice : TInvoice;
var
Mapper : TDataSetMapping;
begin
Mapper := TDataSetMapping.Create(cds);
Mapper.Value := Invoice;
// CDS is now populated with the values stored in Invoice
end;
If you are looking for paid one, I have something for you. Support simple types, memorystream class as memo field, and sub-object. Work from delphi 7 and xe. Something below nature. Can be used binding for editing also
{$M+}
TSubInfo = class
publish
property AMem: TMemoryStream read ... write ....
property ADat: TDateTime read ... write ....
end;
TInvoice = class
publish
property AInt: Integer read ... write ...
property AStr: string read ... write ...
property ASubInfo: TSubInfo read ... write ...
end;
{$M-}
var
DataSet: TObjectDataSet; // is decendent from TDataSet
Invoice: TInvoice;
begin
Invoice := TInvoice.Create...
DataSet := TObjectDataSet.Create...;
DataSet.BindObject := Invoice;
DataSet.Active := True;
.....
Contact me as apz28 at hotmail dot com
精彩评论