Czytam drugi rozdział podręcznika do Delphi i nie za bardzo rozumiem strukturę TMessage.
Chodzi o case skąd się bierze parametr Integer w niej ? :|
http://4programmers.net/Delphi/Kompendium/Rozdzia%C5%82_5#id-Struktura-TMsg
type
TMessage = packed record
Msg: Cardinal;
case Integer of
0: (
WParam: Longint;
LParam: Longint;
Result: Longint);
1: (
WParamLo: Word;
WParamHi: Word;
LParamLo: Word;
LParamHi: Word;
ResultLo: Word;
ResultHi: Word);
end;
Napisałem mini-programik który miał mi wyjaśnić to i owo, ale po jego użyciu rozumiem jeszcze mniej.
Kod
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMainForm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
pos: TLabel;
pos_y: TLabel;
pos_x: TLabel;
wiadomosc: TLabel;
private
procedure WmLButtonDown(var Msg : TMessage); message WM_LBUTTONDOWN;
public
{ Public declarations }
end;
function CardToStr(Number: Cardinal) : String;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
{ TMainForm }
procedure TMainForm.WmLButtonDown(var Msg: TMessage);
begin
pos.Caption := IntToStr(Msg.LParam);
pos_x.Caption := IntToStr(LOWORD(Msg.LParam));
pos_y.Caption := IntToStr(HIWORD(Msg.LParam));
wiadomosc.Caption := CardToStr(Msg.Msg);
end;
function CardToStr(number: Cardinal) : String;
var
s: string;
begin
s := '';
if number = 0 then s := '0' else
while number > 0 do begin
s := chr(number mod 10+48) + s;
number := number div 10;
end;
Result := s;
end;
end.
Formularz:
object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'MainForm'
ClientHeight = 213
ClientWidth = 426
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 112
Top = 80
Width = 37
Height = 13
Caption = 'Normal:'
end
object Label2: TLabel
Left = 112
Top = 99
Width = 10
Height = 13
Caption = 'Y:'
end
object Label3: TLabel
Left = 112
Top = 118
Width = 10
Height = 13
Caption = 'X:'
end
object pos: TLabel
Left = 176
Top = 80
Width = 105
Height = 13
end
object pos_y: TLabel
Left = 176
Top = 99
Width = 105
Height = 13
end
object pos_x: TLabel
Left = 176
Top = 118
Width = 105
Height = 13
end
object wiadomosc: TLabel
Left = 112
Top = 144
Width = 52
Height = 13
Caption = 'wiadomosc'
end
end