Board index » delphi » typecasting a record?

typecasting a record?

I have the following in one of my apps:

procedure WMGetMinMaxInfo(var Msg:TMessage); message WM_GetMinMaxInfo;

procedure TSomeForm.WMGetMinMaxInfo;
var pminmaxinfo:^TMinMaxInfo;
begin
  inherited;
  pminmaxinfo:=pointer(msg.lparam);
  pminmaxinfo^.ptMinTrackSize.x:=470;
  pminmaxinfo^.ptMinTrackSize.y:=320;
end;

Now... How do I typecast msg so that I don't need to declare that pointer?
I've been trying for so long now, that it's almost become an obsession.

Declaring a message cracker is probably the right thing to do, but I'd
like to get the typecast right for future use so to speak...

TIA

=\
 *=- R.Moberg, author of CD-Player Pro! ftp.cica.indiana.edu:
=/                                      /win3/sounds/cdppro45.zip

 

Re:typecasting a record?


In article WSdAmq9V5s0H07...@oslonett.no, mober...@oslonett.no (Rune Moberg) writes:

Quote
>I have the following in one of my apps:

>procedure WMGetMinMaxInfo(var Msg:TMessage); message WM_GetMinMaxInfo;

>procedure TSomeForm.WMGetMinMaxInfo;
>var pminmaxinfo:^TMinMaxInfo;
>begin
>  inherited;
>  pminmaxinfo:=pointer(msg.lparam);
>  pminmaxinfo^.ptMinTrackSize.x:=470;
>  pminmaxinfo^.ptMinTrackSize.y:=320;
>end;

>Now... How do I typecast msg so that I don't need to declare that pointer?
>I've been trying for so long now, that it's almost become an obsession.

>Declaring a message cracker is probably the right thing to do, but I'd
>like to get the typecast right for future use so to speak...

What's wrong with typecasting a pointer?  This is very common,
especially in Windows where you typecase the lParam argument
in hook functions.

Anyway, I found when dealing with Window messages, Delphi has
taken care of some of the burden.  Any time you process a
Windows message, Delphi (at leat 100% of the time I've looked)
provides a type for the message.  The type resembles the
message preceeded with the character 'T'.  For your case you
should rewrite your procedure declaration as:

  procedure WMGetMinMaxInfo (var Msg:TWMGetMinMaxInfo); message WM_GetMinMaxInfo;

Look up the topic TWMGetMinMaxInfo on how to use the message.
I forget which file it is in, but if you have the VCL source,
you can find an example usage of the message.  Below is another
example.

  procedure TForm1.WMGetMinMaxInfo (var Msg: TWMGetMinMaxInfo);
  begin
    with Msg.MinMaxInfo^ DO
      begin
      PtMaxTrackSize := Point (Screen.Width, 10);
      PtMinTrackSize := Point (200, 100);
      end;
    Msg.Result := 0;
  end;

Best regards,
Michael Vincze
m...@asd470.dseg.ti.com

Other Threads