Left side cannot be assigned to record type

I am trying to upgrade my application from Delphi 2007 to Delphi 10 Seattle. I understand that a record must be copied to a local variable before the change, and then assigned back. I try to do the same, but I still get an error that I cannot assign to the left side. Can someone help.

procedure TMydlg.WMGetMinMaxInfo(var Msg:TMessage);
var
     MinMaxInfo: TMinMaxInfo;
begin
   inherited;
   MinMaxInfo := (PMinMaxInfo(Msg.LParam)^);

   with MinMaxInfo do
   begin

      ptMinTrackSize.X := MinWidth;
      ptMinTrackSize.Y := MinHeight;
      ptMaxTrackSize.X := MinWidth;

   end;

   // Error here. Left side cannot be assigned to
   (PMinMaxInfo(Msg.LParam)^) := MinMaxInfo;

TMinMaxInfo is Winapi.windows

+4
source share
2 answers

This is because you are not using a record type, not a pointer type.

Change the code as follows:

procedure TMydlg.WMGetMinMaxInfo(var Msg: TMessage);
begin
  with pMinMaxInfo(Msg.LParam)^ do
  begin    
    ptMinTrackSize.X := MinWidth;
    ptMinTrackSize.Y := MinHeight;
    ptMaxTrackSize.X := MinWidth;      
  end;
end;

I created a dummy test program:

procedure TForm9.FormCreate(Sender: TObject);
var
  MinMaxInfo: pMinMaxInfo;
  Msg: TMessage;
begin
  MinMaxInfo := new(pMinMaxInfo);
  Msg.LParam := integer(MinMaxInfo);
  WMGetMinMaxInfo(Msg);
  Assert( pMinMaxInfo(Msg.LParam)^.ptMinTrackSize.X = 10);
end;

procedure TForm9.WMGetMinMaxInfo(var Msg: TMessage);
var
  MinMaxInfo: pMinMaxInfo;
begin
  MinMaxInfo := pMinMaxInfo(Msg.LParam);

  with MinMaxInfo^ do
  begin

    ptMinTrackSize.X := 10;
    ptMinTrackSize.Y := 10;
    ptMaxTrackSize.X := 10;
  end;    
end;
-3
source

- , . , :

type
  TMyRecord = record
  end;

procedure Foo;
var
  rec1, rec2: TMyRecord;
begin
  rec1 := rec2;   // compiles
  (rec1) := rec2; // E2064 Left side cannot be assigned to
end;

.

, . , . Serg , , (...) , . , .

, .

(PMinMaxInfo(Msg.LParam)^) := MinMaxInfo;

PMinMaxInfo(Msg.LParam)^ := MinMaxInfo;

, , , . , LParam .

:

procedure TMydlg.WMGetMinMaxInfo(var Msg:TMessage);
var
  pmmi: PMinMaxInfo;
begin
  inherited;
  pmmi := PMinMaxInfo(Msg.LParam);
  pmmi.ptMinTrackSize.X := MinWidth;
  pmmi.ptMinTrackSize.Y := MinHeight;
  pmmi.ptMaxTrackSize.X := MinWidth;
end;

dereference ^, . , :

pmmi^.ptMinTrackSize.X := MinWidth;
pmmi^.ptMinTrackSize.Y := MinHeight;
pmmi^.ptMaxTrackSize.X := MinWidth;
+9

Source: https://habr.com/ru/post/1611243/


All Articles