Solved

disabling all buttons on a panel

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

695 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