Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-07

Subroutine ?

17 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Terry A. Haimann
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?

Reply by email

Hans-Peter Diettrich
to Terry A. Haimann
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

Reply by email

Frederic Da Vitoria
to Hans-Peter Diettrich: This code disables all components owned by form: for i := 0 to form.Components.Count - 1…

2013/7/31 Hans-Peter Diettrich

Show quoted text 16 lines
Terry A. Haimann schrieb: 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

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.

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130731/929547df/attachment.html>

Reply by email

Mattias Gaertner
to Frederic Da Vitoria
Show quoted text 23 lines
2013/7/31 Hans-Peter Diettrich > Terry A. Haimann schrieb: > > 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 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

Reply by email

Graeme Geldenhuys
to Terry A. Haimann: I am sure this is a dumb ?, but I want a subroutine that will change all of the…
Terry A. Haimann wrote
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.

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 -

Reply by email

Chavoux Luyt

Hi Mattias

Show quoted text 10 lines
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 Just a related question on this:

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>

Reply by email

Terry A. Haimann
to Mattias Gaertner: 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.

Mattias Gaertner wrote 18 lines
On Tue, 30 Jul 2013 22:53:40 -0500 "Terry A. Haimann" wrote: > 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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Frederic Da Vitoria
to Terry A. Haimann

2013/7/31 Terry A. Haimann

Show quoted text 25 lines
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. On Wed, 2013-07-31 at 07:45 +0200, Mattias Gaertner wrote: > On Tue, 30 Jul 2013 22:53:40 -0500 > "Terry A. Haimann" wrote: > > > 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

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)?

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130731/4b6e078d/attachment.html>

Reply by email

Hans-Peter Diettrich
to Frederic Da Vitoria: 2013/7/31 Hans-Peter Diettrich Previous answers made me wonder: are you sure you meant…
Show quoted text 14 lines
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 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.

Components[] contains the components *owned* by the form, while Controls[] contains only the top-level controls, whose *Parent* is the form.

DoDi

Reply by email

Hans-Peter Diettrich
to Chavoux Luyt: Hi Mattias What happens afterwards when I say Form1.Enabled:=true; ? If some controls…
Show quoted text 6 lines
On 31 July 2013 11:00, < <mailto:>> wrote: TComponent does not have Enabled. So the above code does not work. TControl has Enabled.

Thanks, I missed that.

Show quoted text 11 lines
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 Just a related question on this: 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?

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

Reply by email

Terry A. Haimann
to Mattias Gaertner: 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.

Mattias Gaertner wrote 44 lines
On Wed, 31 Jul 2013 10:04:49 +0200 Frederic Da Vitoria wrote: > 2013/7/31 Hans-Peter Diettrich > > > Terry A. Haimann schrieb: > > > > 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 > > > 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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Chavoux Luyt: 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

Reply by email

Mattias Gaertner
to Terry A. Haimann: Interesting and I didn't know you could do that. But, more of what I have in mind is. I…
Show quoted text 9 lines
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.

What is the question?

Mattias

Reply by email

Frederic Da Vitoria
to Hans-Peter Diettrich: Components[] contains the components *owned* by the form, while Controls[] contains only…

2013/7/31 Hans-Peter Diettrich

Show quoted text 20 lines
Frederic Da Vitoria schrieb: 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 > > > 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. > Components[] contains the components *owned* by the form, while Controls[] contains only the top-level controls, whose *Parent* is the form.

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;
Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130731/fb95bd64/attachment.html>

Reply by email

Hans-Peter Diettrich
to Frederic Da Vitoria
Show quoted text 14 lines
2013/7/31 Hans-Peter Diettrich < <mailto:>> Components[] contains the components *owned* by the form, while Controls[] contains only the top-level controls, whose *Parent* is the form. 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

Reply by email

Frederic Da Vitoria
to Hans-Peter Diettrich

2013/7/31 Hans-Peter Diettrich

Show quoted text 20 lines
Frederic Da Vitoria schrieb: > 2013/7/31 Hans-Peter Diettrich < <mailto: > >> > Components[] contains the components *owned* by the form, while > Controls[] contains only the top-level controls, whose *Parent* is > the form. > > > 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;

Yes, I saw I missed that one later :-P

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130731/48a0d2c3/attachment.html>

Reply by email