[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PostMessage with more then 2 parameters

Posted on 2004-10-05
8
Medium Priority
?
286 Views
Last Modified: 2010-04-05
I need to use the PostMessage command, but I also have 3 parameter to pass...
What would be the best solution in such case...

Thanks for your help!
0
Comment
Question by:PaulP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12233433
first describe how you are planning on using this message, from application to application?

you could just send the pointer to an structure where you have the 3 or whatever fields, that then would become "parameters"
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12235036
type
   Params = record
     Param1 : Integer;
     Param2 : String;
     Param3 : Real;
   end;

  PostMessage(Handle, WM_CUSTOMMESSAGE, @Params, 0);

  inside you WM_CUSTOMMESSAGE definition, you declare one Params variables and take the address of it from Msg.wParam
0
 

Author Comment

by:PaulP
ID: 12236186
Thanks Ivanov!
You seem to be on the right track to help me...
However, I cannot make it work...

I have two window, one with several buttons that call procedures to the other window..

So I have this...
type
 TActionParams = record
     ParamW : Integer;
     ParamL : Integer;
     Param1 : Integer;
     Param2 : Integer;
     Param3 : Integer;
     Param4 : Integer;
   end;
......

procedure callAction(A,B,C);
Var ActionParams: TActionParams;
Begin
   ActionParams.Param1:=A;
   ActionParams.Param2:=B;
   ActionParams.Param3:=C;
   PostMessage(Self.Handle,UM_CallActionFromButton,@ActionParams,0);
End;

.....

procedure TLJManagerMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
Var ActionParams: TActionParams;
Begin

     Case msg.message of
       UM_CallActionFromButton: begin
        ActionParams:=msg.wParam;
        CallActionItems(ActionParams.ParamW,ActionParams.ParamL,ActionParams.Param1,0,0,0,1);
      End;
End;

Buit this doesn't work as there's something I don;t get...  
this line
 PostMessage(Self.Handle,UM_CallActionFromButton,@ActionParams,0);
Give me an error as compile time... "Incompatible Types: Integer and Pointer
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12236417
// Here it is ... nice example

unit Unit1;

interface

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

const
  WM_CALLACTIONFROMBUTTON = WM_USER + 1;

type

 TActionParams = record
   ParamW : Integer;
   ParamL : Integer;
   Param1 : Integer;
   Param2 : Integer;
   Param3 : Integer;
   Param4 : Integer;
 end;


  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure OnMyNewMessage(var Msg: TMessage); message WM_CALLACTIONFROMBUTTON;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.OnMyNewMessage(var Msg: TMessage);
var
  params   : ^TActionParams;
  addr     : Pointer;
begin
  // get the address of Params structure
  addr := Ptr(Msg.wParam);
  params := addr;
  if params <> nil then
    // params fetched
    ShowMessage(IntToStr(params.Param3))
  else
    ShowMessage('Error');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Params    : TActionParams;
begin
  // initialize the parameters
  with Params do
    begin
      ParamW := 0;
      ParamL := 1;
      Param1 := 2;
      Param2 := 3;
      Param3 := 4;
      Param4 := 5;
    end;
  // send to application itself
  SendMessage(Handle, WM_CALLACTIONFROMBUTTON, Integer(@Params), 0);
end;

end.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12236434
I used SendMessage, but now I tried it with PostMessage - the same result - it is working :))
0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12237891
a little another way:

TActionParams = class(TObject)
   ParamW : Integer;
   ParamL : Integer;
   Param1 : Integer;
   Param2 : Integer;
   Param3 : Integer;
   Param4 : Integer;
 end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Params    : TActionParams;
begin
  // initialize the parameters
 Params := TActionParams.Create;
  with Params do
    begin
      ParamW := 0;
      ParamL := 1;
      Param1 := 2;
      Param2 := 3;
      Param3 := 4;
      Param4 := 5;
    end;
  // send to application itself
  PostMessage(Handle, WM_CALLACTIONFROMBUTTON, Integer(Params), 0);
end;

procedure TForm1.OnMyNewMessage(var Msg: TMessage);
begin
  // get the address of Params structure
  with TActionParams(Msg.wParam) do begin
    ShowMessage(IntToStr(Param3))
  end;
end;
0
 

Author Comment

by:PaulP
ID: 12343284
Ok, Sorry for the delay...

I used Vadim method (simpler) and it works... Thanks!

But this seems to have a problem with memeory leaks...
Maybe it's just me doing the wrong thing..

So anyway, I made a small modification to the message handling procedure

Here's what I'm doing:

//The calling procedure
procedure TFormTouchPanel.callActionDown(A: word);
var
  ItemB: pButtonSetup;
  ItemA: pActionCommand;
  I:Integer;
  ActionParams: TActionParams;
begin
    ItemB := TouchButtonList[A];
    ActionParams := TActionParams.Create;
    With ItemB^.DownAction do begin
      With ActionParams do begin
        CmdNo:=action[0];
        CmdType:=action[1];
        Param1:=action[2];
        Param2:=action[3];
        Param3:=action[4];
        Origin:=OriginTouchButton;
      End;
    End;
    PostMessage(MainForm.handle,UM_CallAction,Integer(ActionParams),0);
End;
-------------------------------------

procedure TMainForm.CallActionMessage(var Msg: TMessage);
begin
      With TActionParams(Msg.WParam) do begin
        CallActionItems(CmdNo,CmdType,Param1,Param2,Param3,Origin);
           FreeAndNil(TActionParams(msg.WParam));
      End;
End;

I free/nil the ActionParams after... is this the right way to do it?

Thanks!
0
 
LVL 6

Accepted Solution

by:
vadim_ti earned 1000 total points
ID: 12343305
yes, you need to free object when you do not need it more.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question