2013-05-29 32 views
2

我只是好奇,爲什麼你可以刪除窗體上的TSQLConnection,它會增加LeftTop性質的.dfm(TSQLConnection)爲什麼Left和Top屬性僅在.dfm文件中可用?

object Form1: TForm1 
    ... 
    object SQLConnection1: TSQLConnection 
    Left = 8 
    Top = 8 
    end 
end 

但是,當你在代碼中創建它的LeftTop性能不

interface 

type 
    TForm1 = class(TForm) 
    SQLConnection1: TSQLConnection; 
    procedure FormCreate(Sender: TObject); 
    private 
    { Private declarations } 
    FSQLCon: TSQLConnection; 
    public 
    { Public declarations } 
    end; 

implementation 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    FSQLCon := TSQLConnection.Create(Self); 
    FSQLCon.Left := 280; 
    FSQLCon.Top := 200; 
end; 

編譯:

[DCC Error] Unit1.pas(30): E2003 Undeclared identifier: 'Left' 
[DCC Error] Unit1.pas(31): E2003 Undeclared identifier: 'Top' 
TSQLConnection類的成員

爲什麼某些房產只能在.dfm中轉讓?您是否不能分配以(.dfm)形式設置的代碼(.pas)中的所有屬性?

僅供參考 - 用Delphi XE2(更新3)

回答

5

性質LeftTop爲TComponent真的不存在。在ReadPropertyWriteProperties使用的DefineProperties中爲設計者設置。

看看classes.pas。

+2

謝謝。 +1指向'classes.pas'和'DefineProperties'。 –

+1

+1。就像一個註釋:你會發現這非常可視化控件('TDataSource',ADO組件等)。它們沒有運行時可見性,所以它們沒有位置信息的實際屬性。 IDE添加僞位置(頂部和左側),以便在設計時顯示在適當的位置。 –

相關問題