Recent

Author Topic: Variable RESULT contain the result of the previously called function  (Read 1578 times)

mihey78

  • Newbie
  • Posts: 4
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
 form1.caption:='test '+inttostr(12345);
 memo1.Text:=txt;
end;
//
function TForm1.txt:string;
begin
result:=result;
end;
//
Why does the variable RESULT contain the result of the previously called function inttostr?

Thaddy

  • Hero Member
  • *****
  • Posts: 19017
  • Glad to be alive.
Re: Variable RESULT contain the result of the previously called function
« Reply #1 on: December 23, 2017, 08:22:31 am »
Because the result variable or register is not cleaned up, so the right - old result - is assigned to the left - new - result.
This is by accident and depends on platform and optimizations.
You can not rely on this behavior. Any in between calls would possibly trash the result anyway.

Anyway it of course is bad code.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

 

TinyPortal © 2005-2018