Jump to content
egnew

How to fix W1055 Published Caused RTTI ($M+) Warning

Recommended Posts

I receive this warning when compiling a package:

[dcc32 Warning] Indigo.EventHandlers.pas(11): W1055 PUBLISHED caused RTTI ($M+) to be added to type 'TisEventHandler'

 

Documentation at https://docwiki.embarcadero.com/RADStudio/Sydney/en/W1055_Published_caused_RTTI_($M%2B)_to_be_added_to_type_'%s'_(Delphi)s says:

Quote

You added a 'PUBLISHED' section to a class that was not compiled while the {$M+}/{$TYPEINFO ON} switch was in effect, or without deriving from a class compiled with the {$M+}/{$TYPEINFO ON} switch in effect.

The TypeInfo standard procedure requires a type identifier as its parameter. In the code above, 'NotType' does not represent a type identifier.

To avoid this error, ensure that you compile while the {$M+}/{$TYPEINFO ON} switch is on, or derive from a class that was compiled with {$M+}/{$TYPEINFO ON} switch on.


The above description means nothing to me.  How do I  eliminate the warning from my package?

 

Here is the code associated with the warning:

type
  TisEventHandler = class
  published
    procedure isPrintScreenClick(Sender: TObject);
  end;

Thanks

Share this post


Link to post

Usually published directive is used in Delphi component streaming system for properties in components that will be set in design time and saved as part of form, frame or data module.

 

You have used it for declaring a method and this is not a common use case (unless you want to find and invoke the method by using its name through RTTI). You probably wanted to use public directive instead of published in your code. This will remove the warning.

Share this post


Link to post

I dynamically generate applications from text.  This requires me to locate events by name.  I am currently allowing either an event handler on a form or a built-in handler. 

 

The code I am using is this:

function GetNotifyEvent (const p_MethodName: String; p_Form: TForm): TNotifyEvent;
var
  v_Method: TMethod;
begin
  v_Method.Data := Pointer(p_Form);
  v_Method.Code := p_Form.MethodAddress(p_MethodName);
  if v_Method.Code = nil then
    Result := BuiltInEvent(p_MethodName)
  else
    Result := TNotifyEvent(v_Method);
end;

 

Quote

Note: You can use MethodAddress for published methods only.

Since I am using MethodAddress, I must publish methods I want to find by name.  This is easy and is the approach I am using.

 

I am open to other solutions.  But my question is how to get rid of the warning from the compiler.

 

Edited by egnew

Share this post


Link to post
1 hour ago, egnew said:

Since I am using MethodAddress, I must publish methods I want to find by name.  This is easy and is the approach I am using.

Well in that case you should do what the warning suggests. Add {M+} compiler directive before the class declaration or you can inherit from TPersistent which has RTTI generation turned on.

 

type
  {$M+}
  TisEventHandler = class
  published
    procedure isPrintScreenClick(Sender: TObject);
  end;

 

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×