Re: Help - What is this code used for ?




"Eddy Fontaine" <someone@xxxxxxxxxxxx> wrote in message
news:438b3d2d$0$10963$ba620e4c@xxxxxxxxxxxxxxxxx
>I found this code in the INDY 9 basic TCPClient demo, and i have no idea
> what it is used for...

> procedure TfrmMain.LockControls(ALock: Boolean);
> var
> i : integer;
> begin
> for i := 0 to componentcount-1 do
> if TControl(Components[i]).Tag = 99 then
> TControl(Components[i]).Enabled := ALock;
> end;

The code has a bug, at least IMO. tForm.Components has an entry type of
tComponent, not tControl. It is possible to have a non tControl component
on a form. The reason that the code doesn't fail is that Tag is declared in
tComponent and I presume that the author has only set the Tag of components
of type tControl to 99. However the code would have been tighter if it were
written

if Components [i].Tag = 99
then begin
Assert (Components [i] is tControl);
tControl (Components [i]).Enabled := aLock;
end;

or

if (Components [i].Tag = 99) and (Components [i] is tControl)
then tControl (Components [i]).Enabled := aLock;

By the looks of things the code is used to enable / disable a group of
controls on the main form.


.



Relevant Pages

  • Re: Help - What is this code used for ?
    ... > controls on the main form. ... It is possible to have a non tControl component ... The reason that the code doesn't fail is that Tag is declared ...
    (comp.lang.pascal.delphi.misc)
  • Re: Parental Control required
    ... base classes like TPersistent, TComponent, TControl, and TWinControl, ...
    (alt.comp.lang.borland-delphi)
  • Re: Clone a existing object?
    ... function CloneComponent(AAncestor: TComponent): TComponent; ... if not Assignedthen exit; ... if AAncestor is TControl ...
    (borland.public.delphi.non-technical)