谁能帮我一把,我被困的一周了,谢了!代码如下:(是控件开发的,用TCollectionItem,TCollection,Tpersistent;用Tpersis

  • 主题发起人 主题发起人 YongSoft
  • 开始时间 开始时间
Y

YongSoft

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能帮我一把,我被困的一周了,谢了!代码如下:(是控件开发的,用TCollectionItem,TCollection,Tpersistent;用Tpersisten的写的类调用TCollection写的类,在设计时没有反映,帮我一把?) (50分)<br />unit SRep;

interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Math,Printers,DB,FileCtrl,extctrls,StdCtrls,
Menus,Registry;
Type

TDrawReport=Class;

{labBorder}//标注边框
TLabBorder=Class(Tpersistent)
Private
FTopLine : Boolean;
FLeftLine : Boolean;
FRightLine : Boolean;
FBottomLine : Boolean;
FLineWidth : Integer;
FWidth : Double;
FHeight : Double;
Public
Constructor Create();
Destructor Destroy;Override;
Procedure Assign(Source : TPersistent);OverRide;
Published
Property TopLine : Boolean Read FTopLine Write FTopLine;
Property LeftLine : Boolean Read FLeftLine Write FLeftLine ;
Property RightLine : Boolean Read FRightLine Write FRightLine ;
Property BottomLine: Boolean Read FBottomLine Write FBottomLine;
Property LineWidth : Integer Read FLineWidth Write FLineWidth;
Property Width : Double Read FWidth Write FWidth ;
Property Height : Double Read FHeight Write FHeight ;
End;

{标注}
TLbl=Class(TCollectionItem)
Private
FLabCap : String;
FLabel : String;
FLeft : Double;
FTop : Double;
FCapRect : TRect;
FFont : TFont;
FBorder : TLabBorder;
FMove : Boolean;
Protected

Procedure SetFont(NewFont : TFont);
Procedure SetLeft(NewLeft : Double);
Procedure SetTop(NewTop : Double);
Public

Function GetOwner : Tpersistent ; OverRide;
Constructor Create(Collection: TCollection);Override;
Destructor Destroy;Override;
procedure Assign(Source: TPersistent);Override;
Published

Property Font : TFont Read FFONT Write SetFont Stored TRue;
Property Left : Double Read FLeft Write SetLeft;
Property Top : Double Read FTop Write SetTop;
Property Border : TLabBorder Read FBorder Write FBorder;
End;

TLabClass =Class oF TLbl;

{标注集}
TLbls=Class(TCollection)
Private
FRControl : TDrawReport;
Function GetItem( Index : Integer) : TLBL;
Procedure SetITem(Index : Integer;Value : TLBL);
Protected
Procedure Update(Item : TCollectionItem );OverRide;
Public
Constructor Create ({LabClass : TLabClass });
Destructor Destroy; override;
Function Add : TLbl;
Function GetOwner : Tpersistent ; OverRide;
Property ITems[Item : Integer] : TLBL Read GetItem Write SetITem;Default;
End;

TDrawReport=Class(Tpersistent)
Private
FLBL : TLBLs;//标注
Protected
Public
Constructor Create;
Destructor destroy ; override;
Procedure Assign(Source : Tpersistent);OverRide;
published
Property LabCap : TLbls Read FLBL Write FLBL;//设计时在Object Inspector 没有任何反应。为什么?谁能帮我一把
End;

TReportControl=Class(TScrollingWinControl)
Private
FDrawReport : TDrawReport;
FLBL : TLBLs;//标注
Public
Constructor Create(AOwner: TComponent);override;
Destructor destroy ; override;
Published
Property Font;
Property Color;
property Align;
property AutoScroll;
Property ShowHint;
Property DrawReport: TDrawReport Read FDrawReport Write FDrawReport;
Property LabCap : TLbls Read FLBL Write FLBL;//设计时能在Object Inspector 中能调用属性编辑器
End;
Procedure Register;
implementation
{注册组件}
Procedure Register;
Begin
RegisterComponents('报表',[TReportControl]);
End;
{TLabBorder}
Constructor TLabBorder.Create( );
Begin
inherited Create;
FLineWidth := 2;
FTopLine :=False;
FLeftLine :=False;
FRightLine :=False;
FBottomLine:=False;
End;

Destructor TLabBorder.Destroy;
Begin
inherited Destroy;
End;

Procedure TLabBorder.Assign(Source : TPersistent);
Begin
IF Self=Source Then Exit;
MessageBeep(0);
End;

{TLabCap}

Procedure TLbl.SetFont(NewFont : TFont); //设置字体
Begin
FFont.Assign(NewFont);
End;

Procedure TLbl.SetLeft(NewLeft : Double);
Begin
IF NewLeft=FLeft Then Exit;
FLeft := NewLeft;
End;

Procedure TLbl.SetTop(NewTop : Double);
Begin
IF NewTop=FTop Then Exit;
FTop := NewTop;
End;



Constructor TLbl.Create(Collection: TCollection);
Begin
inherited Create(Collection);
FBorder :=TLabBorder.Create;
FLabCap :='';
FLeft :=1;
FTop :=1;
FFont := TFont.Create;
FFont.Name:='宋体';
FFont.Size:=9;
FFOnt.Style:=[];
FCapRect.Left:=0;
FCapRect.Top:=0;
FCapRect.Right:=10;
FCapRect.Bottom:=10;

End;

Destructor TLbl.Destroy;
Begin
FFont.Free;
FBorder.Free;
inherited Destroy;
End;

Function TLbl.GetOwner : Tpersistent ;
Begin
Result := (Collection As TLbls).FRControl;
End;

procedure TLbl.Assign(Source: TPersistent);
Begin
IF Self=Source Then Exit;
inherited Assign(Source);
End;


{TBLS}
Function TLbls.Add : TLbl;
Begin
Result := TLbl(Inherited Add);
End;

Function TLbls.GetItem( Index : Integer) : TLBL;
Begin
Result := TLbl(Inherited GetItem(Index));
End;
Procedure TLbls.SetITem(Index : Integer;Value : TLBL);
Begin
Inherited SetItem(Index,Value);
End;

Constructor TLbls.Create();
Begin
Inherited Create (TLBL);

End;

Destructor TLbls.Destroy;
Begin
Inherited Destroy;
End;

Procedure TLbls.Update(Item : TCollectionItem );
BEgin
inherited Update(Item);
End;

Function TLbls.GetOwner : Tpersistent ;
Begin
Result := FRControl;
End;
/////////////////////////////////////////////
Constructor TDrawReport.Create();
Begin
Inherited Create();

FLBL := TLBLs.Create();
End;

Destructor TDrawReport.destroy ;
Begin
FLBL.Free;
FLBL:=Nil;
Inherited Destroy;
End;

Procedure TDrawReport.Assign(Source : TPersistent);
Begin
IF Self=Source Then Exit;
MessageBeep(0);
End;

Constructor TReportControl.Create(AOwner: TComponent);
Begin
Inherited Create(AOwner);
Width := 185;
Height := 41;
FDrawReport :=TDrawReport.Create();
FLBL :=TLBLs.Create();
End;

Destructor TReportControl.destroy ;
Begin
FDrawReport.Free;
FDrawReport:=Nil;
// FLBL:=Nil;
Inherited Destroy;
End;


end.
帮我一把,谢了!
 
这个问题我也遇见过,TCollection要在设计期被正确使用,它需要有一条路径能通过
GetOwner找到包含它的控件。VCL提供了TOwnedCollection允许在创建时提供一个Owner,
但如果它的Owner是一个TPersistent对象的话,该TPersistent对象也应该override
GetOwner方法返回上一级的Owner,直到控件为止。
在这个代码中,你可以用TOwnedCollection来代替TCollection,并在 TDrawReport中
override GetOwner 返回控件实例。
(该问题由好友 何清 提供解决)
 
幫你解決了,給錢吧.是TDrawReport的owner問題.
TDrawReport=Class(Tpersistent)
Private
FLBL : TLBLs;
FOwner: TPersistent;//add
Protected
Public
Constructor Create(Owner: TPersistent);//change
Destructor destroy ; override;
Procedure Assign(Source : Tpersistent);OverRide;
function GetOwner: TPersistent; override; //add getowner
published
Property LabCap : TLbls Read FLBL Write FLBL;
End;
////
Constructor TDrawReport.Create(Owner: TPersistent);
Begin
inherited Create;
FOwner := Owner;//add
FLBL := TLBLs.Create();
End;
function TDrawReport.GetOwner: TPersistent; //add
begin
Result := FOwner;
end;
///////////////
Constructor TReportControl.Create(AOwner: TComponent);
Begin
Inherited Create(AOwner);
Width := 185;
Height := 41;
FDrawReport :=TDrawReport.Create(self);//add self
FLBL :=TLBLs.Create();
End;
 

Similar threads

I
回复
0
查看
527
import
I
I
回复
0
查看
682
import
I
I
回复
0
查看
728
import
I
I
回复
0
查看
632
import
I
后退
顶部