Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#3

AW: Pointer aus SendMessage nicht dereferenzierbar?

  Alt 30. Aug 2011, 20:28
Delphi-Quellcode:
type
  TMyRecord = record
    MyInt: Integer;
    MyShortString: ShortString;
  end;
  PMyRecord = ^TMyRecord;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    MyRecord: PMyRecord;
  public
    { Public declarations }
    procedure WndProc(var Message: TMessage); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  WM_PUFF = WM_USER + 1;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyRecord := new(PMyRecord);
  MyRecord.MyInt := 42;
  MyRecord.MyShortString := 'Keine Panik.';
  SendMessage(Form1.Handle, WM_PUFF, 0, Integer(MyRecord)); // Kein @. MyRecord ist schon ein Pointer.
end;

procedure TForm1.WndProc(var Message: TMessage);
var
  MyInt: Integer;
  MyShortString: ShortString;
begin
  inherited;
  case Message.Msg of
    WM_PUFF: begin
        MyInt := PMyRecord(Message.LParam).MyInt;
        MyShortString := PMyRecord(Message.LParam).MyShortString;
        ShowMessage(IntToStr(MyInt) + ' ' + MyShortString);
        Dispose(MyRecord);
      end;
  end;
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat