<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello, I have a hard time trying to understand what you want to
test.</p>
<p>In your functions, you are using a record, not a class or a
pointer to record or an object.</p>
<p>The personrecord just behave in your parameters and return value
as an Integer or a String, and your fillchar doesn't write outside
of the memory allocated for you junkvar, so I don't see what can
go wrong.</p>
<p>If you trace the address of person.name like this:</p>
<pre>//begin code
begin
person := newperson();
writeln('1, person.name address: ', IntToHex(Int64(Pointer(@(person.name)))));
fillchar(junkvar, junkvar_size, 'a');
person2 := newperson();
fillchar(junkvar, junkvar_size, 'b');
person := modperson(person, 'Martin');
person := modperson(person2, 'Maria');
writeln('2, person.name address: ', IntToHex(Int64(Pointer(@(person.name)))));
{writeln(junkvar);}
writeperson(person);
writeperson(person2);
end.
//end code
</pre>
<p>You'll see that the address doesn't change, for example:</p>
<pre>1, person.name address: 000000000050C7F0
2, person.name address: 000000000050C7F0</pre>
<p><br>
</p>
<p>But if you declare your personrecord as a class, the things
doesn't behave the same way:<br>
</p>
<pre>//begin code
const
junkvar_size = 20000000;
type
personclass = class
name: string;
end;
var
person: personclass;
person2: personclass;
junkvar: array[1..junkvar_size] of char;
function newperson(): personclass;
var newp: personclass;
begin
newp:= personclass.Create;
newp.name := '';
newperson := newp;
end;
function modperson(person: personclass; name: string): personclass;
begin
person.name := name;
modperson := person;
end;
procedure writeperson(person: personclass);
begin
writeln(person.name);
end;
begin
person := newperson();
writeln('1, person.name address: ', IntToHex(Int64(Pointer(@(person.name)))));
fillchar(junkvar, junkvar_size, 'a');
person2 := newperson();
fillchar(junkvar, junkvar_size, 'b');
person := modperson(person, 'Martin');
person := modperson(person2, 'Maria');
writeln('2, person.name address: ', IntToHex(Int64(Pointer(@(person.name)))));
{writeln(junkvar);}
writeperson(person);
writeperson(person2);
end.
//end code
</pre>
<pre>You'll get a different address, something like:
</pre>
<br>
1, person.name address: 00007FFFF7F910E8<br>
2, person.name address: 00007FFFF7F91108<br>
<br>
</body>
</html>