Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

disabling all buttons on a panel

Posted on 1998-06-16
4
Medium Priority
?
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

597 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