-2
爲什麼ComponentState
來自下面的代碼,它在Delphi中根據CollectionItem
類未被識別。CollectionItem下的未聲明標識符「ComponentState」
備註:在TMyComp
方法正在工作。
uses
System.Classes, ...
type
TMyComp = class(TComponent)
...
TColumnsItem = class(TCollectionItem)
private
FWidth: Integer;
procedure SetWidth(const Value: Integer);
protected
function GetDisplayName: String; override;
procedure SetIndex(Value: Integer); override;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Width: Integer read FWidth write SetWidth default 90;
end;
procedure TColumnsItem.SetWidth(const Value: Integer);
begin
if FWidth <> Value then
begin
FWidth:= Value;
if csDesigning in ComponentState then //Undeclared identifier 'ComponentState' ???
begin
//do something...
end;
Changed(False);
end;
end;
觀察方興未艾[文檔](http://docwiki.embarcadero.com/Libraries /en/System.Classes.TCollectionItem)。 –
哇!我該怎麼辦呢? – REALSOFO
好的,我找到了答案!我應該使用所有者,如下例所示:'if not(cs在Owner.Header.Treeview.ComponentState中加載)' – REALSOFO