TMessage

Top  Previous  Next

User interface > Translation options > Namespace options > Ignore NODEFINE > TMessage

TMessage is defined in System.Messaging.pas with a NODEFINE directive:

 

type

 

  /// <summary>Base class for all messages</summary>

  TMessageBase = class abstract;

  TMessage = TMessageBase;

  {$NODEFINE TMessage} // Avoid ambiguity with 'Winapi.Messages.TMessage'

 

  TMessage<T> = class (TMessage)

  protected

    FValue: T;

  public

    constructor Create(const AValue: T);

    destructor Destroy; override;

    property Value: T read FValue;

  end;

 

 

Other compilers

 

 

For other C++ compilers then C++Builder the original declaration of the MSG structure in winuser.h should be used, so that there is no conflict with TMessage in 'Winapi.Messages'. To use this code with Delphi2Cpp it would be desirable to rewrite it as follows:

 

type

 

  /// <summary>Base class for all messages</summary>

  TMessage = class

  end;

 

  TMessage<T> = class (TMessage)

  protected

    FValue: T;

  public

    constructor Create(const AValue: T);

    destructor Destroy; override;

    property Value: T read FValue;

  end;

 

The Delphi RTL code should not be changed except for correcting real errors. Therefore a special hack in Delphi2Cpp ensures that the code in question is read as if it were there in the desired form. So the following code:

 

 

procedure Button1Click(Sender: TObject);

var

  MessageManager: TMessageManager;

  Message: TMessage;

begin

  MessageManager := TMessageManager.DefaultManager;

  Message := TMessage<UnicodeString>.Create('Test');

  MessageManager.SendMessage(Sender, Message, True);

end;

 

from

 

https://docwiki.embarcadero.com/CodeExamples/Alexandria/en/System.Messaging_(Delphi)

 

will be converted correctly to:

 

void Button1Click(TObject* Sender)

{

  TMessageManager* MessageManager = nullptr;

  TMessage* Message;

  MessageManager = TMessageManager::ReadPropertyDefaultManager();

  Message = new TMessage__1<UnicodeString>(L"Test");

  MessageManager->SendMessage(Sender, Message, true);

}

 

"TMessage__1" is substituted in the output for the generic "TMessage" type, to avoid conflicts in C++ (It is not allowed there to use a non generic and generic class with the same name  in the same namespace)..

 

 

 

C++Builder

 

 

fur the C++Builder it is necessary additionally to define a refactoring of the non-generic class TMessage to TMessageBase.

 

 

RefactorTMessage

 

 

C++Builder might produce a linker error concerning TMessage__1<UnicodeString>. In that case the addition of a file called instances.pas with the following content helps:

 

unit instances;

 

interface

 

implementation

 

uses System.Messaging;

 

initialization

  TMessage<UnicodeString>.Create.Free;

 

 

end.

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content