我只是好奇为什么你可以在表单上放置 TSQLConnection
,它会将 Left
和 Top
属性添加到 .dfm
:
object Form1: TForm1
...
object SQLConnection1: TSQLConnection
Left = 8
Top = 8
end
end
但是当您在代码中创建它时,Left
和 Top
属性不是 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;
编译:
[DCC Error] Unit1.pas(30): E2003 Undeclared identifier: 'Left'
[DCC Error] Unit1.pas(31): E2003 Undeclared identifier: 'Top'
为什么某些属性只能在 .dfm
中分配?难道您不应该能够分配在表单 (.dfm
) 中设置的代码 (.pas
) 中的所有属性吗?
仅供引用 - 使用 Delphi XE2(更新 3)
最佳答案
TComponent 的属性 Left
和 Top
实际上并不存在。这些是在 ReadProperty
和 WriteProperties
使用的 DefineProperties 中为设计器设置的。
看看classes.pas。
关于delphi - (TSQLConnection) 为什么 Left 和 Top 属性仅在 .dfm 文件中可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806620/