2015-04-01 99 views
0

我试图用FireMonkey平台(XE7)创建一个非常简单的组件(Tgraph)。首先,我创建了两个新类: 1)TGraph(anchestor type TLayout); 2)TMyPlot1D(anchestor type Tpanel); 我保存了两个单元并创建了一个名为“MyPackage”的包。我编译并安装在“Samples”页面中。我打开了一个新的Firemonkey项目,并将TGraph实例拖放到窗体中。一切运作良好。在设计时,我可以看到已定义的组件,并且所有相关单元都可以从主单元看到。相关的代码是在以下几点:FireMonkey组件执行错误

头等舱

unit UMyPlot; 

interface 

uses 
System.SysUtils, System.Classes, FMX.Types, 
FMX.Controls, FMX.StdCtrls; 

type 
TMyPlot1D = class(TPanel) 
private 
    { Private declarations } 
protected 
    { Protected declarations } 
public 
    { Public declarations } 
published 
    { Published declarations } 
end; 

procedure Register; 

implementation 

procedure Register; 
begin 
    RegisterComponents('Samples', [TMyPlot1D]); 
end; 

end. 

二等

unit UMyGraph; 

interface 

uses 
System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Layouts,  
UMyPlot; 

type 
    TMyGraph = class(TLayout) 
    private 
    Plot : TmyPlot1D; 
    public 
    constructor create(Aowner:TComponent); override; 
    end; 

procedure Register; 

implementation 

procedure Register; 
    begin 
    RegisterComponents('Samples', [TMyGraph]); 
    end; 

constructor TMyGraph.create(Aowner: TComponent); 
    begin 
    inherited; 
    Plot := TMyPlot1D.Create(Self); 
    plot.Parent := Self; 
end; 

end. 

,当我尝试运行我的应用程序的问题所示。 我得到了以下错误: “在模块Project1.exe在000A51FA。类未找到类TmyPlot1D异常EClassNotFound”。失败的函数似乎是Application.RealCreateForms。

如果我只拖放TmyPlot1D实例,它在设计时和运行时都会起作用(当然)!

任何想法?

在此先感谢

回答

2

在你TMyGraph.Create要创建一个子对象,情节。这种行为发生在设计时和运行时。

在运行时没有问题,但是问题在发生,因为当您保存设计时,组件的子组件也会流出到FMX文件。

当您运行您的应用程序时,它将表单传入并尝试在设计时创建的TMyGraph和TMyPlot1D子对象中进行流式处理,但失败。即使成功,您也会遇到问题,因为您将在设计时创建TMyPlot1D,并在运行时创建TMyPlot1D。

您可以通过设置解决这个存储:=假的,你在设计时创建的任何孩子,所以你创建方法是这样的:

constructor TMyGraph.Create(Aowner: TComponent); 
begin 
    inherited; 
    Plot := TMyPlot1D.Create(Self); 
    Plot.Parent := Self; 
    Plot.Stored := False; 
end; 

现在我们就来之所以类,如果没有被流媒体系统读入。在FMX中,您需要调用RegisterFMXClasses(Classes unit)以使类可以流式传输到表单中。你需要把这个初始化部分在你的单位的结束,例如:

initialization 
    RegisterFMXClasses([TMYGraph]); 
end. 
+0

非常感谢。现在看来工作。 – Damiano 2015-04-02 12:34:13

0

这个命令是非常重要的:

Tcomponent.Stored:(最终结束之前。)= TRUE;