程序如下:
unit ReportTest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TReportTest = class;
TPageTest = class;
TReportTest = class(TCustomControl)
private
{ Private declarations }
FEditPage:TPageTest;
protected
{ Protected declarations }
//function GetValidRect:TRect;
procedure SetParent(AParent:TWinControl); override;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy; override;
property EditPage:TPagetest read FEditPage ;//编辑页
published
{ Published declarations }
end;
TPageTest = class(TCustomControl)
private
FOwnerReport:TReportTest ;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property OwnerReport:TReportTest read FOwnerReport;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('程智组件', [TReportTest]);
end;
constructor TReportTest.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FEditPage:=Tpagetest.Create(self);
end;
destructor Treporttest.Destroy;
begin
inherited;
if not( csDestroying in EditPage.ComponentState ) then //如果EDITPAGE将要销毁
begin
EditPage.Free;
end;
end;
procedure TReporttest.SetParent(AParent:TWinControl);
begin
inherited;
if not (csDestroying in EditPage.ComponentState) then begin
EditPage.Parent:=Parent;
if Parent<>nil then begin
EditPage.Left :=10;
EditPage.Top:=10;
end;
end;
end;
constructor TPagetest.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if AOwner is TReportTest then
FOwnerReport:=TReportTest(AOwner);
Color :=RGB(255,255,255);//背景色。
Font.Name:='宋体';
Font.Size:=9;
if OwnerReport<>nil then begin
Width:=100;//OwnerReport.ValidRect.Right-OwnerReport.Left ;
Height:=100;//OwnerReport.ValidRect.Bottom-OwnerReport.Top;
end;
end;
destructor TPagetest.Destroy;
begin
inherited Destroy;
end;
end.
问题出在TReporttest.SetParent上,但是我如果不用setparent,报表就不会显示了。
但用了它,onclick事件就不能用了。请问该如何解决。