大家看看我的这个代码有何问题 ( 积分: 50 )

  • 主题发起人 主题发起人 流水先生
  • 开始时间 开始时间

流水先生

Unregistered / Unconfirmed
GUEST, unregistred user!
Taaa= class(TPersistent)
private
Fjj: string;
Fhh: TOurCollection;
FOwner: TComponent;
procedure Sethh(const Value: TOurCollection);
public
constructor Create(AOwner: TComponent);
published
property jj:string read Fjj write Fjj;
property hh:TOurCollection read Fhh write Sethh;//属性编辑时不能弹出编辑框
end;
Tbbb= class(TComponent)
private
Fitem: TOurCollection;
Faa:Taaa;
procedure Setitem(const Value: TOurCollection);
procedure Setaa(const Value: Taaa);
public
constructor Create(AOwner: TComponent); override;
published
property items:TOurCollection read Fitem write SetItem; //属性编辑时能弹出编辑框
property aa:Taaa read Faa write Setaa;
end;

procedure Taaa.Sethh(const Value: TOurCollection);
begin
Fhh.Assign(Value);
end;
constructor Taaa.Create(AOwner: TComponent);
begin
inherited create;
Fhh := TOurCollection.Create(AOwner);
FOwner := AOwner;
end;
procedure Tbbb.Setaa(const Value: TOurCollection);
begin
Faa.Assign(Value);
end;
constructor Tbbb.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Faa := taaa.create
Fitem:=TOurCollection.Create(Self);
end;
procedure Tbbb.Setitem(const Value: TOurCollection);
begin
Fitem.Assign(Value);
end;
procedure Tbbb.Setitem(const Value: Taaa);
begin
Faa.Assign(Value);
end;
以上是我的代码。问题出在注释的那两行,我经验不够还不知道是哪里的问题,还望各位指点。
 
property hh:TOurCollection;// read Fhh write Sethh;//属性编辑时不能弹出编辑框

property items:TOurCollection;// read Fitem write SetItem; //属性编辑时能弹出编辑框
 
晕,刚才没看明白!现在仔细看了一下!!

不对!不好意思
 
各位大虾帮帮忙啊
 
是不是祖先类选择的问题?
 
我把TOurCollection 类帖出来,大虾有空帮我看看到底什么问题啊,跪谢了。
TOurCollection = class;

TOurCollectionItem = class(TCollectionItem)
private
FOurCollection: TOurCollection;
FValue: string;
FText: string;
FBColor: TColor;
FIsSelect: Boolean;
FFColor: TColor;
FMin: integer;
FMax: integer;
FIsEdit: boolean;
Fjj: string;
Fggg: TOurCollection;
procedure SetText(const Value: string);
procedure Setjj(const Value: string);
procedure Setggg(const Value: TOurCollection);
protected
function GetDisplayName: string; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
property Value:string read FValue write FValue;
property Text:string read FText write SetText;
property BColor:TColor read FBColor write FBColor;
property IsSelect:Boolean read FIsSelect write FIsSelect;
property FColor:TColor read FFColor write FFColor;
property Min:integer read FMin write FMin;
property Max:integer read FMax write FMax;
property IsEdit:boolean read FIsEdit write FIsEdit default true;
property jj:string read Fjj write Setjj;
property ggg:TOurCollection read Fggg write Setggg;
end;

TOurCollection = class(TCollection)
private
FOwner: TComponent;
FZTField: String;
FdataField: string;
procedure SetdataField(const Value: string);
procedure SetZTField(const Value: String);
protected
function GetOwner: TPersistent; override;
function GetItem(Index: Integer): TOurCollectionItem;
procedure SetItem(Index: Integer; Value: TOurCollectionItem);
procedure Update(Item: TOurCollectionItem);
public
constructor Create(AOwner: TComponent);
function IndexOf(ztValue:string):integer;
function Add: TOurCollectionItem;
function Insert(Index: Integer): TOurCollectionItem;
property Items[Index: Integer]: TOurCollectionItem read GetItem write SetItem;
published
property ZTField:String read FZTField write SetZTField;
property dataField:string read FdataField write SetdataField;
end;
{ TOurCollectionItem }

procedure TOurCollectionItem.Assign(Source: TPersistent);
begin
if Source is TOurCollectionItem then
Value := TOurCollectionItem(Source).Value
else
inherited;
end;

constructor TOurCollectionItem.Create(Collection: TCollection);
begin
inherited;
FOurCollection := TOurCollection.Create(TOurCollection(Collection).FOwner);
FIsEdit := true;
Fggg := TOurCollection.Create(TOurCollection(Collection).FOwner);
end;

destructor TOurCollectionItem.Destroy;
begin
inherited;
FOurCollection.Free;
end;

function TOurCollectionItem.GetDisplayName: string;
begin
if FText = '' then
Result := Format('ZuangTai %d', [Index])
else
Result := FText;
end;



procedure TOurCollectionItem.Setggg(const Value: TOurCollection);
begin
Fggg.Assign(Value);
end;

procedure TOurCollectionItem.Setjj(const Value: string);
var
i:integer;
begin
if Fjj <> Value then
Fjj := Value;
end;

procedure TOurCollectionItem.SetText(const Value: string);
begin
FText := Value;
GetDisplayName;
end;

{ TOurCollection }

function TOurCollection.Add: TOurCollectionItem;
begin
Result := TOurCollectionItem(Inherited Add);
end;

constructor TOurCollection.Create(AOwner: TComponent);
begin
inherited Create(TOurCollectionItem);
FOwner := AOwner;
// FZTField := 'fzt';
end;

function TOurCollection.GetItem(Index: Integer): TOurCollectionItem;
begin
Result := TOurCollectionItem(inherited GetItem(Index));
end;

function TOurCollection.GetOwner: TPersistent;
begin
Result := FOwner;
end;

function TOurCollection.IndexOf(ztValue: string): integer;
var
i: integer;
begin
Result := -1;
for i := 0 to Count -1 do
begin
if Items.Value = ztValue then
begin
Result := i;
Break;
end;
end;
end;

function TOurCollection.Insert(Index: Integer): TOurCollectionItem;
begin
Result := TOurCollectionItem(Inherited Insert(Index));
end;

procedure TOurCollection.SetdataField(const Value: string);
begin
if FdataField <> Value then
FdataField := Value;
end;

procedure TOurCollection.SetItem(Index: Integer;
Value: TOurCollectionItem);
begin
inherited SetItem(Index, Value);
end;

procedure TOurCollection.SetZTField(const Value: String);
begin
if FZTField <> Value then
FZTField := Value;
end;

procedure TOurCollection.Update(Item: TOurCollectionItem);
begin
Inherited Update(Item);
end;
 
解决了,必须要覆盖getowner
 
后退
顶部