Graeme Geldenhuys wrote 30 lines
Hi,
Why does TControl.AssignTo() have a special case for TCustomAction?
TCustomAction.AssignTo() already does property assignments, so what is
the reason for the special code in TControl.AssignTo?
Here is the code in question:
procedure TControl.AssignTo(Dest: TPersistent);
begin
if Dest is TCustomAction then
with TCustomAction(Dest) do begin
Enabled := Self.Enabled;
Hint := Self.Hint;
Caption := Self.Caption;
Visible := Self.Visible;
OnExecute := Self.OnClick;
HelpContext := Self.HelpContext;
HelpKeyword := Self.HelpKeyword;
HelpType := Self.HelpType;
end
else inherited AssignTo(Dest);
end;
Regards,
- Graeme -
TPersistent introduces 2 methods that help implement a data copy between the controls. 1) the well known and mostly used Assign method where you copy the data from an external control and 2) AssignTo method where you write code to copy the controls values to an external control instead of inheriting the named control. The second method gives you control over 3rd party controls that you do not and should not inherit just to code some data copy compatibility. As an example lets assume that I'm writting a DBGRid descendant/replacement by overriding the assign method I allow my control to copy settings from a TDBGrid, in code that would be MyDBGrid.Assign(DBGrid1);. Overriding the ASsignedTo method you allow the opposite as well ee DBGrid1.Assign(MyDBGrid) will call TMyDBGrid.AssignTo(DBGrid1) and my code will copy my internal data to the dbgrid1.
To sum it up TControl.AssignTo code enables any TControl descendant to
be assigned to a TCustomAction, ee code like ActFileOpen.Assign(Shape1);