...may behave as expected, ...may contain garbage because it isn't initialized.
About nothing
Let's take an example:
program project2;
{$MODE FPC}
{$APPTYPE CONSOLE}
type
TObj = object
Name: string;
end;
TRec = record
Name: string;
end;
procedure Test;
var
Obj: TObj;
Rec: TRec;
begin
Writeln('Name obj: <', Obj.Name, '>');
Writeln('Name rec: <', Rec.Name, '>');
Readln;
end;
begin
Test;
end.
1. Mode is FPC (default for you test also). String is ShortString! (not reference type). In this case, the value of the variable is undefined (by definition). We see garbage in both cases. In your example, the variables are global and are cleared for this reason. But in any case, their behavior is the same!
2. Add {$LONGSTRINGS ON}. Yes, everything was clean! Again, in both cases.
Give a real, rather than a hypothetical example, where an objects are working with an error, and a records without error.