delphi - How can I call a procedure (that deals with a message) from another unit? -


i want procedure wminput(var mess: tmessage); message wm_input; placed in separate unit.

should declare same way in other unit (i'm asking if prototype still same procedure wminput(var mess: tmessage); message wm_input;)?
how can call this? following acceptable?

procedure wminput(var msg: tmessage) begin funit:= fotherunit.create(self); funit.wminput(msg); end; 

are there other alternatives?

message handlers methods, , therefore must declared , implemented within same unit class belong to.

that doesn't stop delegating real work other function in unit, though. there's nothing special message handlers in regard. declare whatever function like, , pass whatever parameters need in order accomplish duties. if needs contents of tmessage record, it. however, need know form received message, pass reference that, too. or maybe needs know values of of form's private fields, pass instead.

you make unit handling messages. interface section this:

unit messagehandlers;  interface  uses otherunit;  procedure handlewminput(form: fotherunit; var message: twminput); 

there's nothing designate function handling wm_input messages; message directive classes.

then, implementation section of form's unit can use unit , call functions:

uses messagehandlers;  procedure fotherform.wminput(var message: twminput); begin   handlewminput(self, message); end; 

i've used twminput instead of tmessage. if delphi doesn't declare type (in messages.pas), suggest declare yourself. lets delphi perform message-parameter cracking you. example, declaration below, raw-input handle has better type , name corresponding field in tmessage.

type   twminput = packed record     msg: cardinal;     inputcode: byte;     unused: array[0..2] of byte;     rawinput: hrawinput;     result: longint;   end; 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -