Question
“How can I associate custom info with a hot-clickable component on my report?”
Solution
This example creates a TmyCustomInfo class that stores the CustNo and Country for a customer. The DBText OnDrawCommandCreate event is used to associate an instance of TMyCustInfo with each DrawCommand generated for the page. The DBText OnDrawCommandClick event shows how to access the CustomInfo.
Download: DrawCommandCustInfo.zip
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
{TmyCustInfo This class is used to store customer information for each draw command} TmyCustInfo = class(TComponent) private FCustNo: Integer; FCountry: String; public constructor CreateCustInfo(aOwner: TComponent; aCustNo: Integer; aCountry: String); virtual; property CustNo: Integer read FCustNo; property Country: String read FCountry; end; implementation constructor TmyCustInfo.CreateCustInfo(aOwner: TComponent; aCustNo: Integer; aCountry: String); begin inherited Create(aOwner); FCustNo := aCustNo; FCountry := aCountry; end; procedure TForm3.Button1Click(Sender: TObject); begin ppReport1.Print; end; procedure TForm3.ppDBText1DrawCommandCreate(Sender, aDrawCommand: TObject); var lCustInfo: TmyCustInfo; begin {create customer info} lCustInfo := TmyCustInfo.CreateCustInfo(Self, plCustomer['CustNo'], plCustomer['Country']); {attach to draw command} TComponent(aDrawCommand).Tag := Integer(lCustInfo); end; procedure TForm3.ppDBText1DrawCommandClick(Sender, aDrawCommand: TObject); var lCustInfo: TmyCustInfo; lsCustNo: String; begin {get customer info} lCustInfo := TmyCustInfo(TComponent(aDrawCommand).Tag); lsCustNo := IntToStr(lCustInfo.CustNo); ShowMessage('CustNo: ' + lsCustNo + #13#10 + 'Country: ' + lCustInfo.Country) ; end; |