(TSQLConnection)为什么Left和Top属性仅在.dfm文件中可用?

Jam*_* L. 2 delphi components runtime

我只是好奇为什么你可以删除一个TSQLConnection表单,它将添加LeftTop属性.dfm:

object Form1: TForm1
  ...
  object SQLConnection1: TSQLConnection
    Left = 8
    Top = 8
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当您在代码中创建它时,LeftTop属性不是TSQLConnection该类的成员:

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;
Run Code Online (Sandbox Code Playgroud)

编译:

[DCC Error] Unit1.pas(30): E2003 Undeclared identifier: 'Left'
[DCC Error] Unit1.pas(31): E2003 Undeclared identifier: 'Top'
Run Code Online (Sandbox Code Playgroud)

为什么有些属性仅适用于.dfm?你不能分配.pas在form(.dfm)中设置的所有属性吗?

仅供参考 - 使用Delphi XE2(更新3)

bum*_*mmi 5

TComponent 的属性LeftTop实际上并不存在.在ReadProperty和使用的DefineProperties中为设计器设置WriteProperties.

看看classes.pas.

  • 谢谢.用于指向`classes.pas`和`DefineProperties`的+1. (2认同)