Page 1 of 1
Uniquery1.Assign command
Posted: Tue 03 Mar 2015 14:41
by smelchi
Hi,
Uniquery1.Assign( dmDataModule.Uniquery1) command didn“t copy events from source.
Uniquery1:= dmDataModule.Uniquer1 copy events.
I would like to copy dmDataModule.Uniquery1 on my form without to link directly do dmDataModule.Uniquery1.
Is there another solution?
Thanks.
Re: Uniquery1.Assign command
Posted: Tue 03 Mar 2015 15:11
by AlexP
Hello,
If you want to use the same event in different datasets, it is enough to set the event after calling the Assign method:
Code: Select all
UniQuery2.Assign(UniQuery1);
UniQuery2.AfterOpen := UniQuery1.AfterOpen;
Re: Uniquery1.Assign command
Posted: Fri 03 Apr 2015 20:06
by smelchi
Uniquery1.Assign( dataModule.Uniquery1) copy fielddefs without DisplayLabel.
How can I copy Displaylabel too?
Copying events is OK. Thanks for your answer.
Re: Uniquery1.Assign command
Posted: Mon 06 Apr 2015 07:59
by AlexP
The DisplayLabel property is a property of the TField class, not of FieldDefs. When calling the Assign method, we don't copy Field and FieldDef, they are created on opening the DataSet. You can set the DisplayLabel property for each field in a loop.
Code: Select all
UniQuery2.Assign(UniQuery1);
ShowMessage(IntToStr(UniQuery2.Fields.Count)); //<--0
ShowMessage(IntToStr(UniQuery2.FieldDefs.Count)); //<--0
UniQuery2.OPen;
for i := 0 to UniQuery1.FieldCount - 1 do begin
UniQuery2.Fields[i].DisplayLabel := UniQuery1.Fields[i].DisplayLabel;
end;