procedure TForm_CheckUser.BitBtn1Click(Sender: TObject);
var
  nameset,password,right:String;begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('select name,password,right from userpower where name=:nameset and password=:password ');
  ADOQuery1.Parameters.ParamByName('nameset').Value:=Edit1.Text;
  ADOQuery1.Parameters.ParamByName('password').Value:=Edit2.Text;
  ADOQuery1.Open;
  if i>0 then
  begin
    if not ADOQuery1.IsEmpty then
      begin
        right:=DBGrid1.Fields[2].Value;
        showmessage(right);        if right='operator' then
          begin
          MainForm.Button1.Enabled:=False;
          showmessage('11111111111');
          end;
        MainForm.Show;
      end
  endend;这段代码中有一个奇怪的问题,当我执行到showmessage(right)时,显示的是operator
但是下一句判断语句的结果总是false,如果我把判断语句改成
if not right='operator'
结果就能执行begin里面的内容了,这是为什么呢?

解决方案 »

  1.   

    right:=DBGrid1.Fields[2].Value
    改为: right:=DBGrid1.fields[2].asstring;
    试一下
      

  2.   

    if right='operator' then//改为:right:=DBGrid1.fields[2].asstring='operator'
              begin
              MainForm.Button1.Enabled:=False;
              showmessage('11111111111');
              end;
    应该就没有问题了
      

  3.   

    right='operator' 改为right=='operator'
      

  4.   

    存在数据库中的字符operator左边或右边带有空格等字符,有可能是空格,也有可能是其他非可视字符,试试下面的:
    procedure TForm_CheckUser.BitBtn1Click(Sender: TObject);
    var
      nameset,password,right:String;begin
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('select name,password,right from userpower where name=:nameset and password=:password ');
      ADOQuery1.Parameters.ParamByName('nameset').Value:=Edit1.Text;
      ADOQuery1.Parameters.ParamByName('password').Value:=Edit2.Text;
      ADOQuery1.Open;
      if i>0 then
      begin
        if not ADOQuery1.IsEmpty then
          begin
            right:=trim(DBGrid1.Fields[2].AsString);
            showmessage(right);        if right='operator' then
              begin
              MainForm.Button1.Enabled:=False;
              showmessage('11111111111');
              end;
            MainForm.Show;
          end
      endend;
      

  5.   

    if pchar(right)='operator' then ..试一下