?
Solved

disabling all buttons on a panel

Posted on 1998-06-16
4
Medium Priority
?
169 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 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