Solved

disabling all buttons on a panel

Posted on 1998-06-16
4
153 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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