【发布时间】:2014-11-09 23:05:57
【问题描述】:
我正在将一个大型项目转换为 Firemonkey,我们有一些自定义按钮,这些按钮未显示在表单上。我已将问题隔离到一个非常简单的项目:
使用下面的代码,在移动和桌面上(使用 Delphi XE6 中的默认新应用程序),创建 tTestButton1 可以正常工作,但 tTestButton2 不会显示在表单上。这怎么可能?
type
tTestButton1 = class(TButton);
tTestButton2 = class(tTestButton1);
tMainForm = class(TForm)
private
fTestButton: TButton;
public
constructor Create(aOwner: TComponent); override;
end;
constructor tMainForm .Create(aOwner: TComponent);
begin
inherited;
// fTestButton := tTestButton1.Create(Self); // this works fine (used instead of next line)
fTestButton := tTestButton2.Create(Self); //this button does not show up
fTestButton.Text := 'Test';
fTestButton.Parent := Self;
fTestButton.Visible := True;
fTestButton.Position.X := 20;
fTestButton.Position.Y := 20;
end;
【问题讨论】:
-
+1 个很好的问题,很棒的重现代码,要是他们都这么好就好了
-
可以在 Delphi XE3 中重现。
-
这是设计使然。视觉组件必须注册样式。否则不会显示。在内部,编译器只查找第一个派生类。
-
@DavidHeffernan,在第一个例子中可以找到
ButtonStyle,但在没有注册TestButton1Style的第二个例子中找不到。 -
@DavidHeffernan,在这里讨论,codeverge.com/embarcadero.delphi.firemonkey/…。
标签: delphi firemonkey delphi-xe6