procedure SetVisibleByTags1(Parent: TWinControl; pPrivate,pTest:boolean);
var C:TComponent;
function GetValue(aComponent:TComponent):Boolean;
begin
if aComponent is TControl then result := TControl(aComponent).Visible
else if aComponent is TMenuItem then result := TMenuItem(aComponent).Visible
else result := true;
if acomponent.tag = 22 then result := pPrivate
else if aComponent.Tag = 11 then result := pTest;
end;
begin
for C in Parent do begin
if C is TControl then
TControl(C).Visible := GetValue(C)//pPrivate
else
if C is TMenuItem then
TMenuItem(C).Visible := GetValue(C);//pPrivate;
end;
//parent is always TWinControl
Parent.Visible := GetValue(Parent);
end;
procedure SetVisibleByTags2(Parent:TWinControl; pPrivate,pTest:boolean);
const cPrivTag=22; cTestTag=11;
var I:integer;
procedure SetVis(C:TComponent);
begin
if C is TMenuItem then with C as TMenuItem do
if Tag=cPrivTag then
Visible:=pPrivate
else
if Tag=cTestTag then
Visible:=pTest
else
else
if C is TControl then with C as TControl do
if Tag=cPrivTag then
Visible:=pPrivate
else
if Tag=cTestTag then
Visible:=pTest;
end;
begin
for I:=0 to Parent.ComponentCount-1 do
SetVis(Parent.Components[I]);
end;
procedure SetVisibleByTags3(Parent: TWinControl; pPrivate,pTest:boolean);
function GetValue(aComponent:TComponent; aDefault:Boolean=True):Boolean;inline;//<-I have no idea if it helps but ...
begin
case aComponent.Tag of
22 : Result := pPrivate;
11 : Result := pTest;
else
Result := aDefault;
end;
end;
var C:TComponent;
begin
for C in Parent do begin
if C is TControl then
TControl(C).Visible := GetValue(C,TControl(C).Visible)//pPrivate
else
if C is TMenuItem then
TMenuItem(C).Visible := GetValue(C,TMenuItem(C).Visible);//pPrivate;
end;
//parent is always TWinControl
Parent.Visible := GetValue(Parent,Parent.Visible);
end;
procedure SetVisibleByTags4(Parent:TWinControl; pPrivate,pTest:boolean);
const cPrivTag=22; cTestTag=11;
var I:integer; vThatOne:TComponent;
procedure SetVis(pValue:boolean);
begin
if vThatOne is TMenuItem then with vThatOne as TMenuItem do
Visible:=pValue
else
if vThatOne is TControl then with vThatOne as TControl do
Visible:=pValue;
end;
begin
for I:=0 to Parent.ComponentCount-1 do
begin
vThatOne:=Parent.Components[I];
with vThatOne do
if Tag=cPrivTag then
SetVis(pPrivate)
else
if Tag=cTestTag then
SetVis(pTest);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var I:integer; vPrivate,vTest:boolean;
begin
vPrivate:=true; // Replace with your test, eg parameters.
vTest:=true; // Replace with your test, eg parameters.
I:=Random(4); // Let's use one at random.
case I of
0: SetVisibleByTags1(Self,vPrivate,vTest); // taazz.
1: SetVisibleByTags2(Self,vPrivate,vTest); // Bazza.
2: SetVisibleByTags3(Self,vPrivate,vTest); // taazz.
3: SetVisibleByTags4(Self,vPrivate,vTest); // Bazza.
end;
end;