前几天问了这个问题,大家说用Assign函数
可是当对象中包含其他对象的时候,用该函数,包含的对象就不能赋值了啊包含的对象是指那些被声明为一个属性的其他对象。
比如我要赋值一个对象A,对象B为对象A的一个对象
当我用A.Assign(*)的时候,B还是为空啊
可是当对象中包含其他对象的时候,用该函数,包含的对象就不能赋值了啊包含的对象是指那些被声明为一个属性的其他对象。
比如我要赋值一个对象A,对象B为对象A的一个对象
当我用A.Assign(*)的时候,B还是为空啊
解决方案 »
- delphi窑洞和大富翁都杯具了
- Delphi2009 VCL源代码中大量出现的新的宏定义编译CLR,有什么新的意图或用途呢?
- 在delphi里调用储存过程出错,出错信息是储存过程里的参数没有赋值,高手知道的指点一下,谢谢了~
- 高手一定要进来,高分求一个算法。
- 目前安全性高的加密解密算法或控件是什么?
- 怎样让Edit控件只接受数字的输入?
- 1000分求救!!谁知道把系统的邮箱设为Outlook Express而不要Microsoft Outlook??
- 临时表字段的问题,搞了一天也搞不定
- 这个SQL语句哪有问题?
- 送分的题目!关于三层的!
- 一道大学里的题,请大家帮忙看一看
- 有关文件追加写入!在线等待!各位大侠们,多谢!!!
Only the common properties shared by both source and destination Series are copied.
private
procedure AssignError(Source: TPersistent);
protected
procedure AssignTo(Dest: TPersistent); virtual;
procedure DefineProperties(Filer: TFiler); virtual;
function GetOwner: TPersistent; dynamic;
public
destructor Destroy; override;
procedure Assign(Source: TPersistent); virtual;
function GetNamePath: string; dynamic;
end;是虚的
To militant(小猪油)
假定类里面的对象的Assign是正确的,那么就OK了,如果这些对象的Assign也不能完全复制,那么原则上本来就应该重写Assign,不存在麻烦的问题。
另外,TPersistent的Assign是怎么实现的阿??
procedure TPersistent.Assign(Source: TPersistent);
begin
if Source <> nil then Source.AssignTo(Self) else AssignError(nil);
end;procedure TPersistent.AssignTo(Dest: TPersistent);
begin
Dest.AssignError(Self);
end;procedure TPersistent.AssignError(Source: TPersistent);
var
SourceName: string;
begin
if Source <> nil then
SourceName := Source.ClassName
else
SourceName := 'nil';
raise EConvertError.CreateResFmt(@SAssignError, [SourceName, ClassName]);
end;完全看不出哪里在复制procedure TBitmap.Assign(Source: TPersistent);
var
DIB: TDIBSection;
begin
if (Source = nil) or (Source is TBitmap) then
begin
EnterCriticalSection(BitmapImageLock);
try
if Source <> nil then
begin
TBitmap(Source).FImage.Reference;
FImage.Release;
FImage := TBitmap(Source).FImage;
FTransparent := TBitmap(Source).FTransparent;
FTransparentColor := TBitmap(Source).FTransparentColor;
FTransparentMode := TBitmap(Source).FTransparentMode;
end
else
begin
FillChar(DIB, Sizeof(DIB), 0);
NewImage(0, 0, DIB, False);
end;
finally
LeaveCriticalSection(BitmapImageLock);
end;
PaletteModified := Palette <> 0;
Changed(Self);
end
else inherited Assign(Source);
end;
我也不知道通用的Assign最开始在哪个类里面实现的,TBitmap的这个assign好像是从TPersistent继承以来头次实现,所以。。要一劳永逸的复制全部元素应该从哪个类继承呢??