假设我有一个要复制的对象。
interface
type
TPerson = Class(TObject)
public
first_name: string;
last_name: string;
address: string;
public
constructor Create;
procedure CopyTo(var s1, s2, s3: string);
...
implementation
...
procedure TPerson.CopyTo(var s1, s2, s3: string)
begin
s1 := first_name;
s2 := last_name;
s3 := address;
end;
end.
然后我可以像这样使用我的课程:
...
var
name1, name2, address: string;
begin
person := TPerson.Create;
person.first_name = 'John';
person.last_name = 'Doe';
person.address = '10 Downing Street';
person.CopyTo(name1, name2, address);
end;
但是如果我对复制地址不感兴趣,我希望能够像这样使用它
...
var
name1, name2: string;
begin
person := TPerson.Create;
person.first_name = 'John';
person.last_name = 'Doe';
person.address = '10 Downing Street';
person.CopyTo(name1, name2);
// Some bad legacy code that has a lot more unstructured fields
end;
我正在考虑编写一个重载CopyTo(var s1, s2: string)
或使用与我想忘记的字符串数量一样多的缓冲区变量?
有没有更优雅的方式?
谢谢。