Clickable DrawCommand click event not raised in version 14
In the code below I add a Clickable ppDrawShape to the background of each
detail band, in version 12 it worked properly. Since upgrading to 14 the
OnClick event is not fired.
Thanks
unit DrawCommandClickCustInfo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ppDB, ppDBPipe, Db, DBTables, ppPrnabl, ppClass, ppCtrls,
ppBands, ppCache, ppComm, ppRelatv, ppProd, ppReport, ppParameter,
ppDrwCmd, ppDevice,
ppDesignLayer;
type
TmyDrillDownDraw = class(TppDrawShape)
private
FKeyValue: Variant;
protected
public
procedure Assign(Source: TPersistent); override;
function EqualTo(aDrawCommand: TppDrawCommand): Boolean; override;
published
property KeyValue: Variant read FKeyValue write FKeyValue;
end;
TForm3 = class(TForm)
Report: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppFooterBand1: TppFooterBand;
ppDBText1: TppDBText;
dsCustomer: TDataSource;
tblCustomer: TTable;
plCustomer: TppDBPipeline;
Button1: TButton;
Memo1: TMemo;
ppDesignLayers1: TppDesignLayers;
ppDesignLayer1: TppDesignLayer;
//procedure ppDBText1DrawCommandCreate(Sender, aDrawCommand: TObject);
//procedure ppDBText1DrawCommandClick(Sender, aDrawCommand: TObject);
procedure Button1Click(Sender: TObject);
procedure ppDetailBand1BeforeGenerate(Sender: TObject);
private
procedure CreateDrawCommand;
procedure DrawClickEvent(Sender: TObject);
//procedure DrawClickEvent(Sender, aDrawCommand: TObject);
{ Private declarations }
public
{ Public declarations }
end;
{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;}
var
Form3: TForm3;
implementation
{$R *.DFM}
{constructor TmyCustInfo.CreateCustInfo(aOwner: TComponent; aCustNo:
Integer; aCountry: String);
begin
inherited Create(aOwner);
FCustNo := aCustNo;
FCountry := aCountry;
end;}
procedure TForm3.Button1Click(Sender: TObject);
begin
Report.Print;
end;
{procedure TForm3.ppDBText1DrawCommandCreate(Sender, aDrawCommand: TObject);
var
lCustInfo: TmyCustInfo;
begin
lCustInfo := TmyCustInfo.CreateCustInfo(Self, plCustomer['CustNo'],
plCustomer['Country']);
TComponent(aDrawCommand).Tag := Integer(lCustInfo);
end;}
procedure TForm3.ppDetailBand1BeforeGenerate(Sender: TObject);
begin
CreateDrawCommand;
end;
procedure TForm3.CreateDrawCommand;
var
ADraw: TmyDrillDownDraw;
begin
ADraw := TmyDrillDownDraw.Create(Report);
ADraw.Clickable := True;
ADraw.Page := Report.Engine.Page;
ADraw.Band := Report.DetailBand;
ADraw.Top := Report.DetailBand.PrintPosRect.Top + 500;
ADraw.Left := Report.PrinterSetup.PageDef.mmMarginLeft;
ADraw.Width := Report.PrinterSetup.PageDef.mmPrintableWidth;
ADraw.Height := Report.DetailBand.mmHeight - 1000;
ADraw.Pen.Style := psClear;
ADraw.Brush.Style := bsClear;
ADraw.OnClick := DrawClickEvent;
ADraw.KeyValue := plCustomer['CustNo'];
end;
procedure TForm3.DrawClickEvent(Sender: TObject);
begin
ShowMessage('CustNo: ' + TmyDrillDownDraw(Sender).KeyValue);
end;
{procedure TForm3.ppDBText1DrawCommandClick(Sender, aDrawCommand: TObject);
var
lCustInfo: TmyCustInfo;
lsCustNo: String;
begin
lCustInfo := TmyCustInfo(TComponent(aDrawCommand).Tag);
lsCustNo := IntToStr(lCustInfo.CustNo);
ShowMessage('CustNo: ' + lsCustNo + #13#10 +
'Country: ' + lCustInfo.Country) ;
end;}
{ TmyDrillDownDraw }
procedure TmyDrillDownDraw.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if not(Source is TmyDrillDownDraw) then
Exit;
FKeyValue := TmyDrillDownDraw(Source).KeyValue;
end;
function TmyDrillDownDraw.EqualTo(aDrawCommand: TppDrawCommand): Boolean;
begin
Result := inherited EqualTo(aDrawCommand);
if aDrawCommand is TmyDrillDownDraw then
Result := Result and (FKeyValue =
TmyDrillDownDraw(aDrawCommand).KeyValue);
end;
initialization
RegisterClasses([TmyDrillDownDraw]);
finalization
UnRegisterClasses([TmyDrillDownDraw]);
end.
detail band, in version 12 it worked properly. Since upgrading to 14 the
OnClick event is not fired.
Thanks
unit DrawCommandClickCustInfo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ppDB, ppDBPipe, Db, DBTables, ppPrnabl, ppClass, ppCtrls,
ppBands, ppCache, ppComm, ppRelatv, ppProd, ppReport, ppParameter,
ppDrwCmd, ppDevice,
ppDesignLayer;
type
TmyDrillDownDraw = class(TppDrawShape)
private
FKeyValue: Variant;
protected
public
procedure Assign(Source: TPersistent); override;
function EqualTo(aDrawCommand: TppDrawCommand): Boolean; override;
published
property KeyValue: Variant read FKeyValue write FKeyValue;
end;
TForm3 = class(TForm)
Report: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppFooterBand1: TppFooterBand;
ppDBText1: TppDBText;
dsCustomer: TDataSource;
tblCustomer: TTable;
plCustomer: TppDBPipeline;
Button1: TButton;
Memo1: TMemo;
ppDesignLayers1: TppDesignLayers;
ppDesignLayer1: TppDesignLayer;
//procedure ppDBText1DrawCommandCreate(Sender, aDrawCommand: TObject);
//procedure ppDBText1DrawCommandClick(Sender, aDrawCommand: TObject);
procedure Button1Click(Sender: TObject);
procedure ppDetailBand1BeforeGenerate(Sender: TObject);
private
procedure CreateDrawCommand;
procedure DrawClickEvent(Sender: TObject);
//procedure DrawClickEvent(Sender, aDrawCommand: TObject);
{ Private declarations }
public
{ Public declarations }
end;
{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;}
var
Form3: TForm3;
implementation
{$R *.DFM}
{constructor TmyCustInfo.CreateCustInfo(aOwner: TComponent; aCustNo:
Integer; aCountry: String);
begin
inherited Create(aOwner);
FCustNo := aCustNo;
FCountry := aCountry;
end;}
procedure TForm3.Button1Click(Sender: TObject);
begin
Report.Print;
end;
{procedure TForm3.ppDBText1DrawCommandCreate(Sender, aDrawCommand: TObject);
var
lCustInfo: TmyCustInfo;
begin
lCustInfo := TmyCustInfo.CreateCustInfo(Self, plCustomer['CustNo'],
plCustomer['Country']);
TComponent(aDrawCommand).Tag := Integer(lCustInfo);
end;}
procedure TForm3.ppDetailBand1BeforeGenerate(Sender: TObject);
begin
CreateDrawCommand;
end;
procedure TForm3.CreateDrawCommand;
var
ADraw: TmyDrillDownDraw;
begin
ADraw := TmyDrillDownDraw.Create(Report);
ADraw.Clickable := True;
ADraw.Page := Report.Engine.Page;
ADraw.Band := Report.DetailBand;
ADraw.Top := Report.DetailBand.PrintPosRect.Top + 500;
ADraw.Left := Report.PrinterSetup.PageDef.mmMarginLeft;
ADraw.Width := Report.PrinterSetup.PageDef.mmPrintableWidth;
ADraw.Height := Report.DetailBand.mmHeight - 1000;
ADraw.Pen.Style := psClear;
ADraw.Brush.Style := bsClear;
ADraw.OnClick := DrawClickEvent;
ADraw.KeyValue := plCustomer['CustNo'];
end;
procedure TForm3.DrawClickEvent(Sender: TObject);
begin
ShowMessage('CustNo: ' + TmyDrillDownDraw(Sender).KeyValue);
end;
{procedure TForm3.ppDBText1DrawCommandClick(Sender, aDrawCommand: TObject);
var
lCustInfo: TmyCustInfo;
lsCustNo: String;
begin
lCustInfo := TmyCustInfo(TComponent(aDrawCommand).Tag);
lsCustNo := IntToStr(lCustInfo.CustNo);
ShowMessage('CustNo: ' + lsCustNo + #13#10 +
'Country: ' + lCustInfo.Country) ;
end;}
{ TmyDrillDownDraw }
procedure TmyDrillDownDraw.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if not(Source is TmyDrillDownDraw) then
Exit;
FKeyValue := TmyDrillDownDraw(Source).KeyValue;
end;
function TmyDrillDownDraw.EqualTo(aDrawCommand: TppDrawCommand): Boolean;
begin
Result := inherited EqualTo(aDrawCommand);
if aDrawCommand is TmyDrillDownDraw then
Result := Result and (FKeyValue =
TmyDrillDownDraw(aDrawCommand).KeyValue);
end;
initialization
RegisterClasses([TmyDrillDownDraw]);
finalization
UnRegisterClasses([TmyDrillDownDraw]);
end.
This discussion has been closed.
Comments
I have the same problem.
DrawComman.OnClick event don't save (restore) from archive file.
But new TppScrollableScreenDevice store all pages in file.
I found next decisions for this problem:
1. Set Report.PreviewFormSettings.SinglePageOnly = True
in this case all will be worked as in RB 12.
2. If this is possible - move DrawClickEvent in TmyDrillDownDraw
and assign OnClick event in TmyDrillDownDraw constructor:
constructor TmyDrillDownDraw.Create(AOwner: TComponent);
begin
inherited;
OnClick := DrawClickEvent;
end;
3. Look in TppReport.DoDrawCommandClick method realization.
You can used next hook:
a) Create some named TppPrintable descendant in TForm3 constructor
(TppShape as example):
const
sInternalShapeName = 'InternalShape';
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
FInternalShape := TppShape.Create(Self);
FInternalShape.Name := sInternalShapeName;
FInternalShape.OnDrawCommandClick :=
InternalShapeDrawCommandClickHandler;
end;
b) Add InternalShapeDrawCommandClickHandler method:
procedure TForm1.InternalShapeDrawCommandClickHandler(Sender,
aDrawCommand: TObject);
begin
DrawClickEvent(aDrawCommand);
end;
c) Modify CreateDrawCommand method:
procedure TForm1.CreateDrawCommand;
begin
...
ADraw.OnClick := FInternalShape.DrawCommandClickEvent;
ADraw.ComponentName := sInternalShapeName;
end;
4. Ask digital-metaphors add check for store TppScrollableScreenDevice
cache in memory.
PS.
May be you don't know. I ask digital-metaphors add
Band.OnCreateDrawCommand event.
Now (that's more good) you can used it instead BeforeGenerate.
PPS.
If you select one of this decisions notify me what one you are selected.
On Thu, 09 Feb 2012 00:13:18 +0300, Jack Harding
Are you using the latest version of ReportBuilder? If not, please
upgrade to 14.03 and re-test. We fixed a number of issues dealing with
drawcommand clicking.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
This is a known issue with RB 14.03 and archive file viewing. The
problem will be fixed for the next release of ReportBuilder.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I used option 2 and it worked for me.
What is the advantage of using OnCreateDrawCommand vs. BeforeGenerate?
Thanks again.
2 big advantages:
1) If Report.PassSettings = psTwoPass then DetailBand.BeforeGenerate will
be calls 2 times.
As result one unnecessary draw command will be created.
2) Band.SpaceUsed does not calculated on BeforeGenerate, but you can used
it in OnCreateDrawCommand event.
This is especial important for reports with DetailBand.PrintHeight =
phDynamic.
Look TppCustomBand.CreateBGDrawCommand or
TppDetailBand.CreateBGDrawCommand for example.
Excuse me for my English.
Suppose, you are understand, what I mean.
PS. Big thanks digital-metaphors for the Band.OnCreateDrawCommand
event!!!
On Thu, 09 Feb 2012 22:01:57 +0300, Jack Harding
Thanks for reporting this.
-
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com