class 尚未注册 TStyledPresentationProxy 的后代

A descendant of TStyledPresentationProxy has not been registered for class

我有一个继承自 TGrid 的自定义网格控件,名为 TFmGrid。此控件在 Rad Studio 10 Seattle Update One 中运行良好。我最近升级到 10.1 Berlin 并开始注意到此错误消息在我 运行 应用程序和设计器中出现在我的 TFmGrid 控件上:

A descendant of TStyledPresentationProxy has not been registered for class TFmGrid. Maybe it is necessary to add the FMX.Grid.Style module to the uses section

下图显示了错误消息如何显示在我的网格控件上:

我开始按照消息的建议进行操作,并将 #include <FMX.Grid.Style.hpp> 添加到我的 TFmGrid 控件的头文件中,但这似乎什么也没做。

就尝试注册 TStyledPresentationProxy 的后代而言,我不确定从哪里开始。我发现 this documentation 关于一种方法:

Attempts to register the presentation proxy class with the specified name or the specified combination of control class and control type.

所以我假设我需要使用此方法或至少类似的东西,但我不明白我应该如何调用此方法。

但是这就提出了我在哪里调用这段代码的问题?

我的自定义控件在其名称空间中有一个名为 Register() 的方法,我相信它是在创建控件时由 IDE 自动生成的:

namespace Fmgridu
{
    void __fastcall PACKAGE Register()
    {
        TComponentClass classes[1] = {__classid(TFmGrid)};
        RegisterComponents(L"Kalos FM Controls", classes, 0);
    }
}  

我需要在那里调用什么来注册 TStyledPresentationProxy 的后代吗?解决这个问题的正确方法是什么?

只需重写虚方法 DefinePresentationName 中的 TfmGrid 和 return 网格的演示名称名称:

function TfmGrid.DefinePresentationName: string;
begin
  Result := 'Grid-' + GetPresentationSuffix;
end;

Fm 按字符串名称注册演示文稿并使用 class 名称,因此如果您创建新组件(基于现有组件),您会自动更改 class 名称,因此系统无法为您找到演示文稿.有两种解决方法:

  1. 说您将使用来自 TGrid (DefinePresentationName) 的演示文稿
  2. 为您注册现有的演示文稿class(查看FMX.Grid.Style.pas的初始化部分)

P.S。年前我写过一篇关于它的commoneNew approach of development of FireMonkey control “Control – Model – Presentation”. Part 1希望对你有帮助

很简单: 只需将“StyleBook”组件添加到您的表单中