Mirror

PostMessage to post a string instead of an integer (Views: 722)


Problem/Question/Abstract:

How to use PostMessage to post a string instead of an integer

Answer:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure wmUser(var Msg: TMessage); message WM_USER;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  lP: LPARAM;
begin
  lP := 0; {VERY important}
  string(lP) := Caption + ' Whatever';
  PostMessage(Handle, WM_USER, 0, lP);
end;

procedure TForm1.wmUser(var Msg: TMessage);
begin
  Caption := string(Msg.LParam);
  string(Msg.LParam) := ''; {VERY important}
end;

end.

<< Back to main page