Advanced Records and Operator overloading. Assignment deletes existing values.
Original Reporter info from Mantis: theo @theo222
-
Reporter name:
Original Reporter info from Mantis: theo @theo222
- Reporter name:
Description:
Please have a look at the attached Code.
The last line:
Writeln(R.fAnyVar);
should return "38" imho, but is undefined actually.
It seems that
R := ansistring('test2');
deletes the existing record values or creates a new instance, where imho it should only perform a SetString on the existing record.
Additional information:
program project1;
{$mode objfpc}{$H+}
{$MODESWITCH ADVANCEDRECORDS}
type
{ TTestAdvRec }
TTestAdvRec = record
private
fText: ansistring;
fAnyVar: integer;
public
procedure SetString(const AValue: ansistring);
function GetString: ansistring;
end;
operator := (r: ansistring) z: TTestAdvRec;
begin
z.SetString(r);
writeln('setting AnsiString');
end;
{ TTestAdvRec }
procedure TTestAdvRec.SetString(const AValue: ansistring);
begin
fText := AValue;
end;
function TTestAdvRec.GetString: ansistring;
begin
Result := fText;
end;
var
R: TTestAdvRec;
begin
R.fAnyVar := 38;
R.SetString('test1');
Writeln(R.GetString);
Writeln(R.fAnyVar);
R := ansistring('test2'); //<----- löscht die Daten des Records bzw. erstellt eine neue Instanz?
Writeln(R.GetString);
Writeln(R.fAnyVar); //<---- gibt 0
end.
Mantis conversion info:
- Mantis ID: 29476
- Build: 3.1.1 [2016/01/22] for x86_64
- Version: 3.1.1