I have the following function :

procedure Foo(const AText: UTF8String; out AValue: UTF8String);
begin
  ShowMessage(AText); //
  AValue := 'A custom value';
end;

procedure AnotherMethod;
var s: UTF8String;
begin
  s := 'Some text';
  Foo(s, s);
  // Do something with `s`
end;


If you have this, the showmessage display an empty string and sometimes the app crashes. I had a doubt so I tried this :

procedure AnotherMethod;
var s, t: UTF8String;
begin
  s := 'Some text';
  t := s;
  Foo(t, s);
  // Do something with `s`
end;

And it works well the app never crash and all my variables are correct. So I guess the two parameters share the same pointer. It seems logic to me in this case.

However, is there a way the compiler produces an error in this case ? I suppose there is a similar case with the 'var' keyword.


--
Damien Gerard
[EMAIL PROTECTED]

"Intelligence is 10 million rules."
   -- Douglas Lenat





_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to