Solved

disabling all buttons on a panel

Posted on 1998-06-16
4
148 Views
Last Modified: 2010-04-04
I want to disable all the buttons placed on a panel at once.

I can disable then using Panel1.enabled := false, but this doesn't give the buttons the disabled look...

So is there a way of disabling all the objects on the panel, AND giving them the disabled appearance, with one function(?) call...

Thanks
0
Comment
Question by:rafy
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 50 total points
ID: 1353076
There is no single function call to do that.

You can do two things to achieve your goal:

1: Derive a new component from TPanel letting it have a new property Enabled

type
  TEnabledPanel = class(TPanel)
  private
    function GetEnabled : Boolean;
    function SetEnabled(Value : Boolean);
  published
    property Enabled : Boolean read GetEnabled write SetEnabled;
  end;

inplementation

function TEnabledPanel.GetEnabled : Boolean;
begin
  Result := inherited Enabled;
end;

function TEnabledPanel.SetEnabled(Value : Boolean);
var
  iControl : Integer;
begin
  if Value<>inherited Enabled then begin
    inherited Enabled := Value;
    for iControl:=0 to ControlCount do begin
      Controls[iControl].Enabled := Value;
    end;
  end;
end;

2. Make a globally accessable function the disables all controls on the panel and call that one in stead of setting the property


function DisablePanel(APanel : TPanel; AEnabled : Boolean);
var
  iControl : Integer;
begin
  with APanel do begin
    for iControl:=0 to ControlCount do begin
      Controls[iControl].Enabled := AEnabled;
    end;
  end;
end;

Why didn't they implement it at Borland:

I think it is a "bug" in the Delphi VCL. The problem with doing it is if you switch the Panel from Enabled to Disabled yopu should store the actual value of the Enabled property of al controls on the panel to be able to restore them.

This isn't supported in the code above but can be implemented.

If you want I can help you with it.

Hope this helps you.

Regards Jacco
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1353077
Okay...you need to change
    for iControl:=0 to ControlCount do begin

to :
    for iControl:=0 to ControlCount -1 do begin

Note if another type of object is dropped on the component how do we handle this...like Buttons and a GroupBox (with more buttons dropped on the GroupBox) dropped on a Panel.  If we disable the GroupBox should we also disable all the GroupBox's children???I think this is why Borland(Inprise) didn't handle this.  Easy enough to fix try this...

procedure EnableChildren(Enabled: boolean; Control: TWinControl);
var
  i: integer;
begin
  for i:= 0 to Control.ControlCount -1 do
    if ((Control.Controls[i]) is TControl) then
      if ((Control.Controls[i]) is TWinControl) and (TWinControl(Control.Controls[i]).ControlCount > 0) then
        CheckChildren(Enabled,TWinControl(Control.Controls[i]))
      else
        TControl(Control.Controls[i]).Enabled := Enabled;
end;

Rick
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1353078
oops...changed the name to better name and forgot to change the recursion call also...

procedure EnableChildren(Enabled: boolean; Control: TWinControl);
var
  i: integer;
begin
  for i:= 0 to Control.ControlCount -1 do
    if ((Control.Controls[i]) is TControl) then
      if ((Control.Controls[i]) is TWinControl) and (TWinControl(Control.Controls[i]).ControlCount > 0) then
        EnableChildren(Enabled,TWinControl(Control.Controls[i]))
      else
        TControl(Control.Controls[i]).Enabled := Enabled;
end;

Rick
0
 

Author Comment

by:rafy
ID: 1353079
Thank you both (but I gotta give the points to Jacco, since he answered first)... exactly what I was looking for.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now