Author: Daniel Wischnewski
Often you disable all Controls within a Panel by simply setting the Enabled
Property of the Panel. It works, however the user does not get any visual feedback.
Answer:
The following component code simply extends the Delphi Panel to properly show the
Enabled State (True/False) within its children.
Extending the control is very simple. All we need to do is to override and extend
the default SetEnabled procedure. The new procedure will first call the original
version and then rotate through all children and copy the state.
There is one drawback although, if there is a disabled control (XYZ) on the panel,
you then disable the panel and enbale it again, the control (XYZ) will be enabled,
too.
Anyway, often it is very useful. Here you go:
1 unit uRealPanel;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ExtCtrls;
8
9 type
10 TRealPanel = class(TPanel)
11 private
12 protected
13 procedure SetEnabled(Value: Boolean); override;
14 end;
15
16 procedure register;
17
18 implementation
19
20 procedure register;
21 begin
22 RegisterComponents('gate(n)etwork', [TRealPanel]);
23 end;
24
25 { TRealPanel }
26
27 procedure TRealPanel.SetEnabled(Value: Boolean);
28 var
29 I: Integer;
30 begin
31 inherited;
32 if csDesigning in ComponentState then
33 Exit;
34 for I := 0 to Pred(ControlCount) do
35 if Controls[I] is TWinControl then
36 (Controls[I] as TWinControl).Enabled := Value;
37 end;
38
39 end.
|