You are not logged in.
Hi Ab,
I am reading your blog "How function results are allocated" (http://blog.synopse.info/post/2012/04/1 … -allocated) and running the code you provided in the blog to understand the problem, but what I have found is that the result is different, it was still 'test' instead of 'toto'. I am running code in Berlin 10.1 as following:
function GetString: string;
// is compiled as procedure GetString(var result: string);
begin
if result='' then
result := 'test' else
writeln('result=',result);
end;
function GetRaise: string;
// is compiled as procedure GetRaise(var result: string);
begin
result := 'toto';
raise Exception.Create('Problem');
end;
var s: string;
begin
// here s=''
s := GetString; // called as GetString(s);
// here s='test'
s := GetString; // called as GetString(s);
// will write 'result=test' on the console
try
s := GetRaise; // called as GetRaise(s);
finally
// here s='toto'
writeln('s=',s);
Readln(s);
end;
end.
Have something changed in Delphi since you wrote the blog or have I done something wrong?
Offline
With Delphi 7 and Delphi 10.1, the last s is 'toto', as expected.
result=test s=toto
This is strange, mine running result did not get "result=test" either!!!
Same result with XE5 and 2007.
Last edited by Bo (2016-10-20 11:11:34)
Offline