• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Grouping Objects

I am wondering if there is a way to group a bunch of objects, like labels or edit boxes, so that i can set them visible false or true in one statement not a whole bunch of statements. Please Help
0
bozo7
Asked:
bozo7
1 Solution
 
MatveyCommented:
Well, I really doubt you can hide all of them with just one statement, however, you can make a TList of these objects, and set the properties in a FOR loop.
0
 
ZifNabCommented:
what you can do is make a descendant of a panel (or any other group component) which when set to invisible, automatically makes all his components invisible? What about it?
0
 
ZifNabCommented:
bozo7,

 come to think of it, panel already supports this offcourse! What a stupid comment I've put above...
 Put all the components in a panel and than make panel invisible. Otherwise if the components are scattered all over a form and can't be put in one panel... make a descendant of TList... (like matvey proposes)

Zif.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
bozo7Author Commented:
I should have clarified.
I also want to enable or disable a group of objects and have the glyphs on the buttons be the disabled glyph not the enabled glyph. When I use a toolbar or panel for this the buttons are disabled but don't show the disabled glyphs.
ZifNab I am rejecting your answer not because it is wrong but because my question was not clear. Sorry
bozo
0
 
JaccoCommented:
You can derive a panel component that does the job for you.

unit GroupPanel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, StdCtrls;

type
  TGroupPanel=class(TPanel)
  private
    FControlsVisible: Boolean;
    FControlsEnabled: Boolean;
    procedure SetControlsVisible(Value: Boolean);
    procedure SetControlsEnabled(Value: Boolean);
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ControlsVisible: Boolean
      read FControlsVisible
      write SetControlsVisible default True;
    property ControlsEnabled: Boolean
      read FControlsEnabled
      write SetControlsEnabled default True;
  end;

implementation

constructor TGroupPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FControlsVisible:=True;
  FControlsEnabled:=True;
end;

procedure TGroupPanel.SetControlsVisible(Value: Boolean);
var
  iControl: Integer;
begin
  if Value<>FControlsVisible then begin
    for iControl:=0 to ControlCount-1 do
      Controls[iControl].Visible:=Value;
    FControlsVisible:=Value;
  end;
end;

procedure TGroupPanel.SetControlsEnabled(Value: Boolean);
var
  iControl: Integer;
begin
  if Value<>FControlsEnabled then begin
    for iControl:=0 to ControlCount-1 do
      Controls[iControl].Enabled:=Value;
    FControlsEnabled:=Value;
  end;
end;

end.
0
 
bozo7Author Commented:
I had to move the SetControlsVisible and SetcontrolsEnabled to the Public section. Otherwise does exaclty what I was looking for.

I really enjoy this exchange of info

bozo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now