请查看TComponent
:
TMyField = class(TCollectionItem)
private
FName: String
FSqlField: TSqlField;
procedure SetName(const Value: String);
procedure SetSqlField(const Value: TSqlField)
published
property Name: String read FName write SetName;
property SqlField: TSqlField read FSqlField write SetSqlField;
end;
TSqlField = class(TPersistent)
private
FAlias: String;
FName: String;
FTable: String;
procedure SetField(Index: Integer; Value: String);
public
procedure Assign(Source: TPersistent); override;
published
property Alias: String index 0 read FAlias write SetField;
property Name: String index 1 read FName write SetField;
property Table: String index 2 read FTable write SetField;
end;
procedure TSqlField.SetField(Index: Integer; Value: String);
var
FOwner: TMyField;
begin
if (Value <> FAlias) or (Value <> FName) or (Value <> FTable) then
begin
case Index of
0: if Value <> FAlias then FAlias:= Value;
1: if Value <> FName then FName:= Value;
2: if Value <> FTable then FTable:= Value;
end;
if FName <> '' then
begin
FOwner:= GetOwner; //Error here: E2010 Incompatible types: 'TMyField' and 'TPersistent'
if FTable <> '' then FOwner.Name:= Format('%s_%s',[FTable,FName])
else FOwner.Name:= FName;
end;
end;
end;
处理SetField
中的TSqlField
方法时,我想从Name
访问该属性TSqlField : TCollectionItem
,以便重命名。
备注:TCollection
的所有者可以是一个或另一个TComponent
。
请提供一些关于如何做到的建议。