例如我想通过中间层一个接口函数,参客户端的每个FORM上通过此函数来判断按钮的权限 因此想传一个FORM给中间层: 如下: procedure SetAllBtnRight(UserCode, MenuCode: string; vself: string); var _RightName: string; _i, _S, _E: integer; _Caption: string; _Self: TForm; begin _Self := application.findcomponet(vSelf) as TForm; _RightName := ''; with DmLeaderBrowse.Dt_GetRight do begin Close; CommandText := ' Declare @s varchar(8000) ' + ' Set @s = '''' ' + ' Select @s = @s + ''['' + r.RightName + '']'' from SmUserMenuRight umr ' + ' Left Join SmRight r on umr.RightCode = r.RightCode ' + ' where umr.UserCode = ''' + UserCode + ''' and umr.MenuCode = ''' + MenuCode + '''' + ' Select @s'; Open; _RightName := Fields[0].AsString; end;
//主要是用在这里遍历所有组件,如果是按钮则判断它的权限: for _i := 0 to _self.ComponentCount - 1 do begin if Copy(LowerCase(_self.Components[_i].Name), 1, 3) = 'btn' then begin if _self.Components[_i].ClassType = TButton then begin _Caption := '[' + trim((_self.Components[_i] as TButton).Caption) + ']'; if Pos(_Caption, _RightName) > 0 then (_self.Components[_i] as TButton).Enabled := true else (_self.Components[_i] as TButton).Enabled := false; end else if _self.Components[_i].ClassType = TBitBtn then begin _Caption := '[' + trim((_self.Components[_i] as TBitBtn).Caption) + ']'; if Pos(_Caption, _RightName) > 0 then (_self.Components[_i] as TBitBtn).Enabled := true else (_self.Components[_i] as TBitBtn).Enabled := false; end else if _self.Components[_i].ClassType = TSpeedButton then begin _Caption := '[' + trim((_self.Components[_i] as TSpeedButton).Caption) + ']'; if Pos(_Caption, _RightName) > 0 then (_self.Components[_i] as TSpeedButton).Enabled := true else (_self.Components[_i] as TSpeedButton).Enabled := false; end else if _self.Components[_i].ClassType = TToolButton then begin _Caption := '[' + trim((_self.Components[_i] as TToolButton).Caption) + ']'; if Pos(_Caption, _RightName) > 0 then (_self.Components[_i] as TToolButton).Enabled := true else (_self.Components[_i] as TToolButton).Enabled := false; end end; end; end;
你传过程不就可以了
实在不行,用dll
因此想传一个FORM给中间层:
如下:
procedure SetAllBtnRight(UserCode, MenuCode: string; vself: string);
var
_RightName: string;
_i, _S, _E: integer;
_Caption: string;
_Self: TForm;
begin
_Self := application.findcomponet(vSelf) as TForm;
_RightName := '';
with DmLeaderBrowse.Dt_GetRight do
begin
Close;
CommandText := ' Declare @s varchar(8000) ' +
' Set @s = '''' ' +
' Select @s = @s + ''['' + r.RightName + '']'' from SmUserMenuRight umr ' +
' Left Join SmRight r on umr.RightCode = r.RightCode ' +
' where umr.UserCode = ''' + UserCode + ''' and umr.MenuCode = ''' + MenuCode + '''' +
' Select @s';
Open;
_RightName := Fields[0].AsString;
end;
//主要是用在这里遍历所有组件,如果是按钮则判断它的权限:
for _i := 0 to _self.ComponentCount - 1 do
begin
if Copy(LowerCase(_self.Components[_i].Name), 1, 3) = 'btn' then
begin
if _self.Components[_i].ClassType = TButton then
begin
_Caption := '[' + trim((_self.Components[_i] as TButton).Caption) + ']';
if Pos(_Caption, _RightName) > 0 then
(_self.Components[_i] as TButton).Enabled := true
else
(_self.Components[_i] as TButton).Enabled := false;
end
else if _self.Components[_i].ClassType = TBitBtn then
begin
_Caption := '[' + trim((_self.Components[_i] as TBitBtn).Caption) + ']';
if Pos(_Caption, _RightName) > 0 then
(_self.Components[_i] as TBitBtn).Enabled := true
else
(_self.Components[_i] as TBitBtn).Enabled := false;
end
else if _self.Components[_i].ClassType = TSpeedButton then
begin
_Caption := '[' + trim((_self.Components[_i] as TSpeedButton).Caption) + ']';
if Pos(_Caption, _RightName) > 0 then
(_self.Components[_i] as TSpeedButton).Enabled := true
else
(_self.Components[_i] as TSpeedButton).Enabled := false;
end
else if _self.Components[_i].ClassType = TToolButton then
begin
_Caption := '[' + trim((_self.Components[_i] as TToolButton).Caption) + ']';
if Pos(_Caption, _RightName) > 0 then
(_self.Components[_i] as TToolButton).Enabled := true
else
(_self.Components[_i] as TToolButton).Enabled := false;
end end;
end;
end;