现在有 EDIT1(值为asdf)
      EDIT2(值为asdfsd)
      EDIT3
             按钮BUTTON
请问在BUTTON的事件中如何写才能满足下面的条件?
当EDIT1获得焦点并且EDIT1的值等于asdf进入form2.
当EDIT2获得焦点并且EDIT2的值等于asdfsd进入form3.
.
.
.
.
.

解决方案 »

  1.   

     
     if (Edit1.Focused) and (Edit1.text = 'asdf') then
       begin
          form2.Show;
       end;
     if (EDIT2.Focused) and (EDIT2.text = asdfsd) then
       begin
          form3.Show;
       end
      //......
      

  2.   


     if (Edit1.Focused) and (Edit1.text = 'asdf') then
       begin
          form2.Show;
       end;
     if (EDIT2.Focused) and (EDIT2.text = 'asdfsd') then
       begin
          form3.Show;
       end
      //......
      

  3.   

    var 
      k:intgeger;
    begin
    if ((TEdit(FindComponent('edit'+inttostr(1)))).Focused)and
       ((TEdit(FindComponent('edit'+inttostr(1)))).Text='asdf') then Form2.ShowModal;
    if ((TEdit(FindComponent('edit'+inttostr(2)))).Focused)and
       ((TEdit(FindComponent('edit'+inttostr(2)))).Text='asdfsd') then Form3.ShowModal;
    end;edit更多的话用循环就OK!!!
      

  4.   

    if (Edit1.Focused) and (Edit1.text = 'asdf') then
       begin
          form2.Show;
       end;
     if (EDIT2.Focused) and (EDIT2.text = asdfsd) then
       begin
          form3.Show;
       end
      

  5.   

    在ButtonClick里,焦点应该转移到Button上了吧,再去判断edit的focused应该不对吧
      

  6.   

    难道你非要这样的东西? if Edit1.text = 'asdf' then 
      begin 
          Edit1.SetFocus;
          form2.Show; 
      end; 
    if EDIT2.text = 'asdfsd' then 
      begin 
          Edit2.SetFocus;
          form3.Show; 
      end 
      

  7.   

    不是这样是,是在EDIT1获得焦点的前提下,在判断EDIT1的text
      

  8.   

    我就不明白了 可以同时有两个焦点吗? 
    一个焦点在button上面  另外还有edit保持着焦点?  这怎么可能 
      

  9.   

    你可以在keypress里面写代码  
    如果edit里面的值等于某个字符串 就弹出窗体
      

  10.   

    这种情况下 焦点确实是在edit上面的  又可以满足条件弹出窗体
      

  11.   

    我的意思就是有若干个EDIT,
      EDIT1
      EDIT2
      EDIT3
      .
      .
      .
    然后一个BUTTON,当EDIT1的内容为蓝色时(就是获得焦点吧),点BUTTON 进入FORM1
                  当EDIT2的内容为蓝色时(就是获得焦点吧),点BUTTON 进入FORM2
                  .
                  .
                  .
      

  12.   

    原来要折中效果,很简单啊,写一个editEnter,然后把你的edit的事件全挂上,然后遍历你的edit,如果sender和edit一样,就将这个edit的tag改为1,如果不一样tag就改为0,
    这样只要判断text和tag就可以得判断你要的东西了
      

  13.   

    把上面那段代码加到Chang事件里,焦点的判断没有必要。
      

  14.   

    procedure TForm1.EditEnter(Sender: TObject);
    var
      i:integer;
    begin  for i:=0 to ControlCount-1 do
      begin
         if (Controls[i] is TEdit) then
         begin
           if TEdit(Controls[i]).Name = TEdit(Sender).Name then
                TEdit(Sender).Tag := 1
           else
                TEdit(Sender).Tag := 0 ;
         end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
       if (Edit1.Tag = 1) and (edit1.Text = 'Edit1') then
           ShowMessage('Edit1');   if (Edit2.Tag =1) and (edit2.Text = 'Edit2') then
           ShowMessage('Edit2');   if (Edit3.Tag =1) and (edit3.Text = 'Edit3') then
           ShowMessage('Edit3');end;
      

  15.   

    这里写错了,应该是    if (Controls[i] is TEdit) then 
        begin
          if TEdit(Controls[i]).Name = TEdit(Sender).Name then
                TEdit(Controls[i]).Tag := 1
          else
                TEdit(Controls[i]).Tag := 0 ;
        end;
      

  16.   

    如果果edit1和edit2条件都成立的情况下,你想怎么显示窗体?
      

  17.   

    EDIT1和EDIT2不可能同时获得焦点。
      

  18.   

    没必要考虑焦点,在Edit中有个Onchange事件在里面写好判断就OK了。
    procedure TForm1.Edit1Change(Sender: TObject);
    begin
      if Edit1.Font.Color = clblue then
      begin
        form2.show;
      end;
    end;
      

  19.   

    谢谢各位! gwhdaxia (阿木)做的是我想要的,可能我表达的不准确,各位没明白我的意思。谢谢大家!
    下午结帖。