I store controls 'visible' and 'enabled' property in DB table. Depending on user's role I make some controls not visible/enabled.
fields of db Table "Controls": id, role_id, form (varchar), comp_name(varchar), visible (boolean), enable (boolean)
query qControls: select * from controls where form=:form
calling of this procedure from OnShow of main form:
application.CreateForm(TForm1, Form1);
FORM := 'Form1';
Form1.showModal;
Called procedure:
procedure RightsOnControls();
var i:integer;
begin
fMain.qControls.Close;
fMain.qControls.Params[0].AsString:= FORM; //FORM is global variable: FORM:='Form1'
fMain.qControls.Open;
if fMain.qControls.RecordCount>0 then begin
while not fMain.Controls.Eof do begin
for I := 0 to form1.ControlCount - 1 do
if uppercase(form1.Controls[i].Name)= uppercase(fMain.qControlsComp_name.AsString) then
begin
form1.Controls[i].Visible:=fmain.qControlsVisible.AsBoolean;
form1.Controls[i].Enabled:=fmain.qControlsEnable.AsBoolean;
end;
fMain.qControls.next;
end;
end;
end;
My questions are:
- how make procedure as general event handler,not for only Form1?
- It finds only controls located on form, not controls located on the panel/Page control (tabsheet). How change it?