Delphi: TByteDynArray problem job length

The question is closed (answer accepted) replaced by Delphi 7: Access violation - TByteDynArray problem )


I have the following delcartion given to me

MyPhoto = class(TRemotable)
private
  FhasPhoto: Boolean;
  FphotoData: TByteDynArray;
published
  property hasPhoto: Boolean read FhasPhoto write FhasPhoto;
  property photoData: TByteDynArray read FphotoData write FphotoData;
end;

I want too

var photo : MyPhoto;
photo := MyPhoto.Create();
SetLength(photo.photoData, 4);

but i get

[Error] mainForm.pas(340): Constant object cannot be passed as var parameter

1) How to encode it correctly, given that I cannot change the definition of the Photo class?
2) can I effectively "dump" any structure in TByteDynArray by simply assigning it?

(as you might have guessed, I'm a BCB guy trying to get into Ddlphi :-)


ps I agree to be able to assign each byte of photo data individually ...

+2
source share
2 answers

Delphi. , , var, SetLength. , , , .

. , , FPhotoData.

+2

:

MyPhoto = class(TRemotable)
  ...
public
  procedure SetSize( aSize : Integer );
end;

procedure MyPhoto.SetSize( aSize : Integer );
begin
  SetLength( FphotoData, aSize );
end; 


var photo : MyPhoto;
photo := MyPhoto.Create();
MyPhoto.SetSize(4);
+1

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


All Articles