2016-07-25 52 views
-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; 
+1

觀察方興未艾[文檔](http://docwiki.embarcadero.com/Libraries /en/System.Classes.TCollectionItem)。 –

+0

哇!我該怎麼辦呢? – REALSOFO

+0

好的,我找到了答案!我應該使用所有者,如下例所示:'if not(cs在Owner.Header.Treeview.ComponentState中加載)' – REALSOFO

回答

0

ComponentStateTComponent下一個屬性。

TCollectionItem下使用是必要的一個FOwner屬性定義與TComponent和等中使用:

if csDesigning in FOwner.ComponentState then 
    begin 
    //do something... 
    end;