Initialise string function result?

This is not a bug, but “feature“:

For a string, dynamic array, method
pointer, or variant result, the
effects are the same as if the
function result were declared as an
additional var parameter
following the
declared parameters. In other words,
the caller passes an additional 32-bit
pointer that points to a variable in
which to return the function result.

I.e. your

function TMyObject.GenerateInfo: string;

Is really this:

procedure TMyObject.GenerateInfo(var Result: string);

Note “var” prefix (not “out” as you may expect!).

This is SUCH un-intuitive, so it leads to all kind of problems in the code. Code in question – just one example of results of this feature.

See and vote for this request.

Leave a Comment