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

标签 delphi runtime components

我只是好奇为什么你可以在表单上放置 TSQLConnection ,它会将 LeftTop 属性添加到 .dfm:

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

但是当您在代码中创建它时,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;

编译:

[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 的属性 LeftTop 实际上并不存在。这些是在 ReadPropertyWriteProperties 使用的 DefineProperties 中为设计器设置的。

看看classes.pas。

关于delphi - (TSQLConnection) 为什么 Left 和 Top 属性仅在 .dfm 文件中可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806620/

相关文章:

architecture - "Reusable Business Component"是神话吗?

html - v-on :click in component not working

json - Delphi 解码 json/utf8 转义文本

android - 如何在 TEdit 处于焦点时隐藏(并再次显示)软键盘 DELPHI XE7

sql-server - 为什么只有部分用户收到错误 : "Connection is busy with results for another command"

java - 检查powerpoint是否已经在Java中打开?

Java 类型转换在 System.out.println 调用中给出编译错误

java - 什么时候在 Java/Gradle 中使用运行时而不是编译时依赖?

Angular4 组件继承与抽象类

Delphi DBGrid 显示压缩行