const ProgramID='P0012';
//要用到实际窗体中的PROGRAMID
procedure TP0012.SetSecurity();
var
  tmpQuy: TAdoQuery;
  strSql: string;
  i: integer;
begin
  tmpQuy := TAdoQuery.Create(nil);
  tmpQuy.Connection := FrmQCDM.ADOCon;
  tmpQuy.SQL.Clear;
  strSql := 'Select * From V_F00950  Where 用户名=' + '''' + SysParam.UserCode + '''' +
    //' AND 安全类型=' + '''' + '2' + '''' +
    ' And 程序号=' + '''' + ProgramID + '''' ;//+
    //'and (屏幕名称=' + '''' + 'ALL' + '''' +
    //' OR 屏幕名称=' + '''' + ScreenID + '''' +
    //') ORDER BY 屏幕名称';
  tmpQuy.SQL.Add(strSql);
  tmpQuy.Open;
  tmpQuy.First;
  if not tmpQuy.eof then
  begin
    if tmpQuy.FieldByName('运行').AsBoolean = False then
    begin
      MessageDlg('对不起,您没有权限运行该程序或画面!' + char(13) +
        '请与系统管理员联系', mtInformation, [MBOK], 0);
      self.Close;
     // Result := False;
      Exit;
    end
  end
  else
  begin
    MessageDlg('对不起,您没有权限运行该程序或画面!' + char(13) +
      '请与系统管理员联系', mtInformation, [MBOK], 0);
    self.Close;
   // Result := False;
    Exit;
  end;
  for i := 0 to self.ComponentCount - 1 do
  begin
    if self.Components[i].ClassName = 'TSpeedButton' then
    begin
      tmpQuy.First;
      while not tmpQuy.eof do
      begin
        if System.pos('EDIT',
          Uppercase(trimright((self.Components[i]).Name))) > 0 then
          TSpeedbutton(self.Components[i]).Enabled :=
            tmpQuy.FieldByName('修改').AsBoolean;
        if System.pos('ADD',
          Uppercase(trimright((self.Components[i]).Name))) > 0 then
          TSpeedbutton(self.Components[i]).Enabled :=
            tmpQuy.FieldByName('增加').AsBoolean;
        if System.pos('EDIT',
          Uppercase(trimright((self.Components[i]).Name))) > 0 then
        begin
          TSpeedbutton(self.Components[i]).Enabled :=
            tmpQuy.FieldByName('选择').AsBoolean;        end;
        if System.pos('COPY',
          Uppercase(trimright((self.Components[i]).Name))) > 0 then
          TSpeedbutton(self.Components[i]).Enabled :=
            tmpQuy.FieldByName('复制').AsBoolean;
        if System.pos('DEL',
          Uppercase(trimright((self.Components[i]).Name))) > 0 then
          TSpeedbutton(self.Components[i]).Enabled :=
            tmpQuy.FieldByName('删除').AsBoolean;        tmpQuy.Next;
      end;
    end;
  end;
 // Result := True;
  tmpQuy.Close;
  tmpQuy.free;end;
这个函数能写在基类中吗?
如何写?

解决方案 »

  1.   

    把PROGRAMID封装成一个全局变量的属性
    private
      FPROGRAMID// 为类中的私有变量
    public
      property PROGRAMID: String read FPROGRAMID write FPROGRAMID;
    然后创建这个类后,给这个属性赋值
      

  2.   

      //取程序号
      ClassName:=mListItem.SubItems[1];
      with TFormClass(GetClass('T'+ClassName)).Create(self) do
      begin
        Caption:=mListItem.SubItems[0];
        PROGRAMID:=ClassName; //
        USERID:=sysparam.UserCode;
        Show;
      end;
    编译通不过?