A descendant of TStyledPresentationProxy has not been registered for class

641 Views Asked by At

I have a custom grid control that inherits from TGrid called TFmGrid. This control was working fine in Rad Studio 10 Seattle Update One. I recently upgraded to 10.1 Berlin and started noticing this error message showing up on my TFmGrid controls both when I run the application and in the designer:

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

The image below shows how the error message shows up on my grid controls:

enter image description here

I started by doing as the message suggests, and adding #include <FMX.Grid.Style.hpp> to the header file of my TFmGrid control, however this seems to have done nothing.

So as far as trying to register a decendant of TStyledPresentationProxy I am not exactly sure where to start. I found this documentation about a method which:

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

So I assume I need to use this method or at least something similar, but I don't understand how I am supposed to go about calling this method.

But then that brings up the question of WHERE do I call this code?

My custom control has a method in its namespace called Register() which I believe was autogenerated by the IDE when the control was created:

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

Do I need to call something in there to register a decendant of TStyledPresentationProxy? What is the proper way to go about this?

3

There are 3 best solutions below

0
Yaroslav Brovin On BEST ANSWER

Just override virtual method DefinePresentationName in you TfmGrid and return name of presentation name for grid:

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

Fm registers presentation by string name and uses class name for it, so if you create new component (based on existed) you automatically change classname, so system cannot find presentation for you. There are two solution:

  1. Said that you will use presentation from TGrid (DefinePresentationName)
  2. Register existed presentation for you class (look at the initialization section of FMX.Grid.Style.pas)

P.S. Year ago i wrote article about it in common eNew approach of development of FireMonkey control “Control – Model – Presentation”. Part 1 I hope it will help you

0
AliReza On

It's simple : Just put "StyleBook" component to your form

0
Maicon Pires On

I had the same issue with a test component I was developing. Complementing Yaroslav Brovin's speech, I solved the problem by adding the class register in the initialization and finalization clauses at the end of the unit, like this:

initialization
  TPresentationProxyFactory.Current.Register(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);

finalization
  TPresentationProxyFactory.Current.Unregister(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);

In my case looks like this:

initialization
  TPresentationProxyFactory.Current.Register(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);

finalization
  TPresentationProxyFactory.Current.Unregister(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);

PS: Don't forget to declare the FMX.Presentation.Factory, FMX.Presentation.Style and FMX.Grid.Style units in the uses clause