我有一段代码,如下所示:
接口部分:
TControlOrganizer = class(TComponent) // a kind of List of TControl
private
FList : TList; //Handling list of TControl
..............
end;
TControlHelperAdd = class // Just for separating value entered by user and value produced by code
private
FOrganizer : TControlOrganizer;
FOrigValue : String;
FUserValue : String;
end;
TControlHelper = class helper for TControl //Basic helper for TControl
private
class var
FAddProp : TControlHelperAdd;
protected
procedure SetOrganizer(Value : TControlOrganizer);
function getOrganizer:TControlOrganizer;
public
class Constructor doinit;
class Destructor deinit;
procedure OrganizerChanged;virtual;
published
Property Organizer:TControlOrganizer read getOrganizer write setOrganizer; //Problem No.1
end;
//Helper for CustomEdit inherited from TControlHelper
TCustomEditHelper = class helper(TControlHelper) for TCustomEdit
protected
procedure OrganizerChanged;override;
end;
//TEdit : interceptor
TEdit= class(StdCtrls.TEdit)
protected
procedure Change;override; //problem No.3
end;
实施部分:
{TControlHelper}
class Constructor TControlHelper.doinit;
begin
FAddProp :=TControlHelperAdd.Create;
end;
class Destructor TControlHelper.deinit;
begin
FreeAndNil(FAddProp);
end;
procedure TControlHelper.OrganizerChanged;
begin
end;
procedure TControlHelper.SetOrganizer(Value : TControlOrganizer);
begin
if FAddProp.FOrganizer<>value then begin
if assigned(FAddProp.FOrganizer) then begin
FAddProp.FOrganizer.remove(self);
end;
FAddProp.FOrganizer:=value;
if assigned(FAddProp.FOrganizer) then begin
FAddProp.FOrganizer.Add(self);
end;
OrganizerChanged; //Problem No.2
end;
end;
function TControlHelper.getOrganizer:TControlOrganizer;
begin
result:=FAddProp.FOrganizer;
end;
{TCustomEditHelper}
procedure TCustomEditHelper.OrganizerChanged; //problem No.2
begin
if assigned(FAddProp) then begin
if assigned(Organizer) then begin
FAddProp.FOrigValue:=Text;
FAddProp.FUserValue:=Text;
end;
end;
end;
{TEdit = Interceptor}
procedure TEdit.Change; //Problem No.3
begin
inherited Change;
FAddProp.FUserValue:=Text;
end;
我发现了 3 个我自己无法解决的问题。
问题 1:已发布的属性属性未显示在对象检查器中。我想我犯了一个错误,在这里忘记了一些东西。
问题 2:如上所示,来自类助手的重写方法没有触发(没有工作)。
问题 3:如上所示的拦截器类中的重写方法没有触发(没有工作)。
任何人都可以帮我找出问题所在吗?感谢您的帮助,并为我糟糕的英语感到抱歉。