delphi对象复制问题(assign?)(100分)

  • 主题发起人 ddzhouqian
  • 开始时间
D

ddzhouqian

Unregistered / Unconfirmed
GUEST, unregistred user!
我程序里有两个对象分别为panel1,panel2,现在要把panel1对象的信息复制给对象panel2。这个两个对象分别为mypanel类的两个实例panel1,panel2,mypanel是我在panel的基础上加了些功能的tpanel,里面加了些事件,还加了两个panel,一个ftimer:ttimer,我现在想把panel1对象的信息复制给panel2,如何实现?当前的panel1的ftimer的事件处于运行状态,正在执行某些事件。
 
D

dxiaoliang

Unregistered / Unconfirmed
GUEST, unregistred user!
用 clone assign 方法就可以了
没有delphi的代码 有c++builder的一点代码 看看把
TBaseClass* TKeyValue::Clone()
{
TKeyValue * result=new TKeyValue();
result->Assign(this) ;
return result;
}

void TKeyValue::Assign(TPara* anotherPara)
{
if (anotherPara==NULL ) return;
TableName =((TKeyValue*)anotherPara)->TableName;
FieldKeyWordColumnName =((TKeyValue*)anotherPara)->FieldKeyWordColumnName;
FieldValueColumnName =((TKeyValue*)anotherPara)->FieldValueColumnName ;
KeyWord =((TKeyValue*)anotherPara)->KeyWord;
Value =((TKeyValue*)anotherPara)->Value;
}
 
D

ddzhouqian

Unregistered / Unconfirmed
GUEST, unregistred user!
to :dxiaoliang
“TableName =((TKeyValue*)anotherPara)->TableName”像这样的写法赋值还是复制,我现在有点糊涂了。
如果这样是复制,那么事件复制如何实现呢?
如:timer2.ontimer:=timer1.ontimer,这样可以吗?
 
S

sunnyboy_delphi

Unregistered / Unconfirmed
GUEST, unregistred user!
panel2.assign(panel1)
这是对象的赋值 不知道楼主是不是这个意思
 

Similar threads

回复
0
查看
789
不得闲
回复
0
查看
658
不得闲
D
回复
0
查看
984
DelphiTeacher的专栏
D
顶部