[Pas2js] TObject.Dispatch messages

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Mar 12 13:19:46 CET 2019


Hi all,

pas2js trunk can now dispatch messages very much like FPC/Delphi.

For example:

type
  TRunMessage = record
    Msg: DWord;
    Result: DWord;
  end;
  THopMessage = record
    MsgStr: String;
    Result: DWord;
  end;

  TEagle = class
    procedure Run(var Msg: TRunMessage); message 123;
    procedure Hop(var Msg: THopMessage); message 'Hop';
  end;

procedure TEagle.Run(var Msg: TRunMessage);
begin
  writeln('TEagle.Run class=',ClassName,' Name="',Name,'" Msg.Msg=',Msg.Msg);
  Msg.Result:=17;
end;

procedure TEagle.Hop(var Msg: THopMessage);
begin
  writeln('TEagle.Hop class=',ClassName,' Name="',Name,'" Msg.MsgStr=',Msg.MsgStr);
  Msg.Result:=18;
end;

var
  Eagle: TEagle;
  RunMsg: TRunMessage;
  HopMsg: THopMessage;
begin
  Eagle:=TEagle.Create;

  RunMsg.Msg:=123;
  RunMsg.Result:=0;
  Eagle.Dispatch(RunMsg);

  HopMsg.MsgStr:='Hop';
  HopMsg.Result:=0;
  Eagle.DispatchStr(HopMsg);

  Eagle.Free;
end;

See here for more details:
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/utils/pas2js/docs/translation.html?view=co#dispatch

Mattias


More information about the Pas2js mailing list