[fpc-pascal] Difference between string and Tbytes as procedure arguments?

Michael Van Canneyt michael at freepascal.org
Sun Nov 5 16:36:10 CET 2023



On Sun, 5 Nov 2023, Bo Berglund via fpc-pascal wrote:

>>
>> You must copy the data. The copy() function can be used for this.
>
> Follow-up question:
>
> Can I change the function declaration like this and preserve the content?
>
> function TSSConnection.ParseCmdFileData(var SSCmdFile: TSSCommandFile; const
> Buf:  TBytes): boolean;

This does not preserve the content. The "const" means you cannot change the
pointer, so

Buf:=a;

will fail

But

Buf[0]:=1;

will still compile.

>
> Or must I copy the argument Buf inside the function to a local BufL version?
> That is what you adviced, right?

Yes.

Mcihael.


More information about the fpc-pascal mailing list