【权限代码】: procedure LevelLoadItems(MyForm:TForm;MyAdoQuery:TClientDataSet); var MMItems:string; cx:Integer; Obj:TComponent; begin MyAdoQuery.Close; MyAdoQuery.CommandText:='select * from LevelInf where GroupName= '''+ Trim(FrmMain.Label8.Text) +''''; MyAdoQuery.Open;
MyAdoQuery.First; while not MyAdoQuery.Eof do begin MMItems:=MyAdoQuery.fieldbyname('SysName').AsString; for cx:=0 to MyForm.ComponentCount - 1 do begin Obj:=TComponent(MyForm.Components[cx]);
if Obj.Name=MMItems then begin if Obj is TButton then begin TButton(Obj).Visible:=True; end;
if Obj is TMenuItem then begin TMenuItem(Obj).Visible:=True; end;
if Obj is TComboBox then begin TComboBox(Obj).Visible:=True; end;
if Obj is TMemo then begin TMemo(Obj).Visible:=True; end;
if Obj is TPanel then begin TPanel(Obj).Visible:=True; end;
if Obj is TTreeViewItem then begin TTreeViewItem(Obj).Visible:=True; end;
function funcShowOnlyControlsAuthorized(AControlsAuthorized: TArray<string>; AControl: TControl): boolean; begin result := false; // if (length(AControlsAuthorized) = 0) or (AControl = nil) then exit; // for var C in AControlsAuthorized do if (C = AControl.ClassName) then exit(true); end;
procedure TForm1.Button2Click(Sender: TObject); var LFoundControlsOnLayout2OnForm2: boolean; LObjectOnLayout2 : TArray<TControl>; begin LFoundControlsOnLayout2OnForm2 := false; // if (Form2 = nil) then Form2 := TForm2.Create(nil); // try // if dont exists a "Layout" on Form2 = exception!!! LFoundControlsOnLayout2OnForm2 := (Form2.LayoutMainForm2.ControlsCount > 0); // LayoutMainOfForm1.DeleteChildren; // // Because when using "xxxx.ADDObject()", the object will be "removed from source" and "added on target"!!! for var i: integer := 0 to (Form2.LayoutMainForm2.ControlsCount - 1) do LObjectOnLayout2 := LObjectOnLayout2 + [Form2.LayoutMainForm2.Controls[i]]; // for var i: integer := 0 to high(LObjectOnLayout2) do begin if funcShowOnlyControlsAuthorized(['TEdit', 'TListBox', 'TLabel'], LObjectOnLayout2[i]) then LayoutMainOfForm1.AddObject(LObjectOnLayout2[i]); // WARNING: "this will remove automatically any object from Form2" end; finally if not LFoundControlsOnLayout2OnForm2 then FreeAndNil(Form2); end; end;
procedure TForm1.FormDestroy(Sender: TObject); begin FreeAndNil(Form2); end;
initialization
ReportMemoryLeaksOnShutdown := true;
end.
此帖子包含附件: 大小:8.0K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
【权限控制代码】 procedure LevelLoadItems(MyForm:TWinControl;MyAdoQuery:TFDQuery); var MMItems:string; cx:Integer; Obj:TComponent; begin MyAdoQuery.Close; MyAdoQuery.SQL.Clear; MyAdoQuery.SQL.Add('select * from LevelInf where GroupName= '''+ FrmMain.GroupName +''''); MyAdoQuery.Open;
MyAdoQuery.First; while not MyAdoQuery.Eof do begin MMItems:=MyAdoQuery.fieldbyname('SysName').AsString; for cx:=0 to MyForm.ComponentCount - 1 do begin Obj:=TComponent(MyForm.Components[cx]);
if Obj.Name=MMItems then begin if Obj is TButton then begin // TWinControl(Obj as TButton).Enabled:=True; TButton(Obj).Enabled:=True; end;
if Obj is TMenuItem then begin TMenuItem(Obj).Enabled:=True; end;
if Obj is TComboBox then begin TComboBox(Obj).Enabled:=True; end;
if Obj is TMemo then begin TMemo(Obj).Enabled:=True; end;
if Obj is TPanel then begin TPanel(Obj).Enabled:=True; end;
//打开窗体的涵数 procedure TFrmMain.OpenForm(AParent: TControl; AForm: TCustomForm); begin while AForm.ChildrenCount>0 do AForm.Children[0].Parent:=AParent; LevelLoadItems(AForm,CDS); {此处是调用权限管理,代码在楼上} end;