【发布时间】:2019-01-22 09:39:50
【问题描述】:
我做了什么?
我正在尝试开发 FMX Gauge 组件。目前它只有一根针。我创建了一个新包并添加了以下代码: 单位 FMX.VDO;
interface
uses
System.SysUtils,
System.Classes,
FMX.Types,
FMX.Controls,
FMX.MultiResBitmap,
FMX.Layouts,
FMX.Objects;
type
TVdoLayout = class(TScaledLayout)
private
FNeedle : TImage;
function GetBitMapNeedle: TFixedMultiResBitmap;
procedure SetBitMapNeedle(const Value: TFixedMultiResBitmap);
function GetValue: Double;
procedure SetValue(const Value: Double);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property BitMapNeedle : TFixedMultiResBitmap read GetBitMapNeedle write SetBitMapNeedle;
property Value : Double read GetValue write SetValue;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TVdoLayout]);
end;
{ TVdoLayout }
constructor TVdoLayout.Create(AOwner: TComponent);
begin
inherited;
Self.Size.Width := 326;
Self.Size.Height := Self.Size.Width;
FNeedle := TImage.Create(Self);
FNeedle.Parent := Self;
FNeedle.Width := 262;
FNeedle.Height := 21;
FNeedle.Position.X := 40;
FNeedle.Position.Y := 270;
FNeedle.Height := Self.Height * 0.04901;
FNeedle.Width := Self.Width * 0.7485;
FNeedle.RotationCenter.X := 0.935;
FNeedle.RotationCenter.Y := 0.27;
FNeedle.RotationAngle := 45;
end;
function TVdoLayout.GetBitMapNeedle: TFixedMultiResBitmap;
begin
Result := FNeedle.MultiResBitmap;
end;
procedure TVdoLayout.SetBitMapNeedle(const Value: TFixedMultiResBitmap);
begin
FNeedle.MultiResBitmap := Value;
end;
function TVdoLayout.GetValue: Double;
begin
Result := FNeedle.RotationAngle;
end;
procedure TVdoLayout.SetValue(const Value: Double);
begin
FNeedle.RotationAngle := Value;
end;
end.
在此之后,我构建了项目并安装了我的组件。
我创建了一个新的 FMX 项目并放置了我的组件。我在设计时加载了一张针的图片。见下文:
在设计时我可以更改属性Value。如果你看到上面的代码,Value 改变了针的RotationAngle。它在设计时完美运行。
有什么问题?
在运行时,当我通过 TEdit 将组件的 Value 属性更改为 90 时,它可以工作,但是会拍摄初始针的快照,如下所示,它似乎是重复的:
我尝试过的其他事情没有成功?
我尝试调用 resize 和 repaint 函数。
还按照@UweRaabe 的建议在创建期间添加了FNeedle.SetSubComponent(True);。
如果我在运行时加载针图像,它可以工作。但这不是一个理想的解决方案。
详情
- 德尔福 10.1 柏林
- FireMonkey(在 Windows 上)
【问题讨论】:
-
你可能被流媒体系统欺骗了。在创建过程中添加 FNeedle.SetSubComponent(True) 是否有效?
-
@UweRaabe 不,它没有。
-
在这种情况下,请提供一个显示错误的最小项目。
-
@UweRaabe,我重新提出了我的问题。我认为现在更容易复制。
-
当您使用 SetSubComponent 进行测试时,您是重新创建 DFM 还是使用现有的进行测试?
标签: delphi components firemonkey