I am sure this is a dumb ?, but I want a subroutine that will change all
of the components of a form to Enabled := False.How do I do this?

Mailing lists / lazarus / 2013-07
17 messages · 6 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
I am sure this is a dumb ?, but I want a subroutine that will change all
of the components of a form to Enabled := False.How do I do this?
I am sure this is a dumb ?, but I want a subroutine that will change all of the components of a form to Enabled := False. How do I do this?
This code disables all components owned by form:
for i := 0 to form.Components.Count - 1 do
form.Components[i].Enabled := False;Untested, eventually Components.Count has to be replaced by ComponentCount.
DoDi
I am sure this is a dumb ?, but I want a subroutine that will change all of the…
I am sure this is a dumb ?, but I want a subroutine that will change all of the components of a form to Enabled := False. How do I do this?
for i:=0 to ControlCount-1 do
Controls[i].Enabled:=false;Mattias
This code disables all components owned by form: for i := 0 to form.Components.Count - 1…
2013/7/31 Hans-Peter Diettrich
Previous answers made me wonder: are you sure you meant "Component", not "Control"? If the form contains non-visual components, this could change the result.
TComponent does not have Enabled. So the above code does not work. TControl has Enabled.
Disabling a control (e.g. no focus, some widgetsets draw them gray) automatically disables child controls. So the easiest way to disable all controls on a form is to set Form1.Enabled:=false.
Mattias
Mattias
I am sure this is a dumb ?, but I want a subroutine that will change all of the…
Terry A. Haimann wroteI am sure this is a dumb ?, but I want a subroutine that will change all of the components of a form to Enabled := False.
Not sure if you wanted controls to be "disabled" or "readonly" (when possible)...
If you wanted the latter, then tiOPF has a component TtiReadOnly that you can drop on a form and simply set ReadOnly = True at runtime, and all is done for you. The TtiReadOnly component also has a few events that you can hook into so you can have more fine grained control over what controls or forms get processed.
http://sourceforge.net/p/tiopf/code/ci/tiopf2/tree/GUI/tiReadOnly.pas
This unit is completely stand-alone and doesn't use any other tiOPF units or code.
Regards,
- Graeme -
Hi Mattias
What happens afterwards when I say Form1.Enabled:=true; ? If some controls were enabled beforehand and some were disabled, will this be remembered or will I need to enable them one-by-one or will all controls be enabled by default?
Cheers
Chavoux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130731/a5dd7e77/attachment.html>
On Tue, 30 Jul 2013 22:53:40 -0500 for i:=0 to ControlCount-1 do…
Interesting and I didn't know you could do that. But, more of what I have in mind is.
I have a bunch of database components on a form, I want them to be enabled only after hitting the edit or insert button on the DbNavigator. Since this is going to occur in multiple points in my button procedure, it would be programmatically better if this could be done in a sub procedure. Also, I have fields that are dependent on other fields, so fieldsz only would become active if fieldx has a 'Y' in it.
2013/7/31 Terry A. Haimann
Hmm, I am still unsure, are you really speaking of components (in which case you may want to do things like connect conditionally) or of controls (you want only to prevent the user from interacting with the form)?
2013/7/31 Hans-Peter Diettrich Previous answers made me wonder: are you sure you meant…
Components[] contains the components *owned* by the form, while Controls[] contains only the top-level controls, whose *Parent* is the form.
DoDi
Hi Mattias What happens afterwards when I say Form1.Enabled:=true; ? If some controls…
Thanks, I missed that.
Enabling/disabling a Parent does not change the Enabled *values* of its child controls. Child controls of a disabled Parent are disabled implicitly, by e.g. message processing logic.
DoDi
On Wed, 31 Jul 2013 10:04:49 +0200 TComponent does not have Enabled. So the above code…
I am talking mostly about TDBEdit and a few TDBComboBox objects.
Hi Mattias What happens afterwards when I say Form1.Enabled:=true; ? If some controls…
[...] > Just a related question on this: What happens afterwards when I say Form1.Enabled:=true; ?
Form1.Enabled does not change the 'Enabled' values of child controls. A control is enabled if itself and all its parents are enabled. See TControl.IsEnabled.
If some controls were enabled beforehand and some were disabled, will this be remembered or will I need to enable them one-by-one or will all controls be enabled by default?
You get the old state. No child property was changed.
Mattias
Interesting and I didn't know you could do that. But, more of what I have in mind is. I…
What is the question?
Mattias
Components[] contains the components *owned* by the form, while Controls[] contains only…
2013/7/31 Hans-Peter Diettrich
OK, but since Components can be Controls or not, they could have an Enabled property or not. So shouldn't the loop actually be something like:
for i := 0 to form.Components.Count - 1 do
if form.Components[i] is TControl
then form.Components[i].Enabled := False; then TControl(form.Components[i]).Enabled := False;DoDi
2013/7/31 Hans-Peter Diettrich
Yes, I saw I missed that one later :-P