这个需要在TMyClass的定义中重载AssignTo方法,在这个方法中把自身的所有属性都赋给Dest参数的相关属性,然后在程序中调用Assign方法来赋值,正如zhongs兄说的那样:ClassB.Assign(ClassA);
Assign方法会直接调用AssignTo方法;
而且TMyClass必须要从TPersistent继承上来,
请看TPicture的源码:
TPicture = class(TInterfacedPersistent, IStreamPersist)
private
...............
protected
procedure AssignTo(Dest: TPersistent)
override;
...........
end;
procedure TPicture.AssignTo(Dest: TPersistent);
begin
if Graphic is Dest.ClassType then
Dest.Assign(Graphic)
else
inherited AssignTo(Dest);
end;