要求:在程序启动后,如果切换输入法后,只要不再次切换,其输入法应一直不变。我把所有控件(输入框、DBGRID等)的 输入模式都设置为DON'T CARE,即事先不设输入法。这样在同一窗体或窗体间切换时都可以不变输入法,但如果点击了DBRID后,再进入另一个窗体,输入法就自动关闭,如不点击DBGRID,一切正常。我都检查了DBGRID的属性了,试问怎么解决?

解决方案 »

  1.   

    用windows api,进入dbgrid前用变量保存输入法,退出后恢复输入法。
      

  2.   

    不能设置IMEName属性,因为输入法是用户进入后随意确定,并不固定的。但要求一旦启动输入法后就应不变,除非自己切换,或退出程序。是不是DBGRID有什么设置不对?
      

  3.   

    错,DBGRID有BUG,
    好像是这里吧
    在DBGrids.pas
    procedure TCustomDBGrid.WMKillFocus(var Message: TMessage);
    begin
      if SysLocale.FarEast then inherited
      else
      begin
        ImeName := Screen.DefaultIme;
        ImeMode := imDontCare;
        inherited;
        if not ((InplaceEditor <> nil) and
          (HWND(Message.WParam) = InplaceEditor.Handle)) then
          ActivateKeyboardLayout(Screen.DefaultKbLayout, KLF_ACTIVATE);
      end;
    end;
      

  4.   

    你可设置程序中的全局变量保存输入法://将本机上的输入法读入Listbox中供用户选择
    procedure TForm6.FormCreate(Sender: TObject);
    begin
    var
      myhkl: hkl;
      i: integer;
    begin
      myHKL:=GetKeyBoardLayOut(0);
      for i := 0 to Screen.Imes.Count-1  do
      begin
          if HKL(Screen.Imes.Objects[i]) = myHKL then
            srf := Screen.Imes.Strings[i];//当前输入法名称,srf为全局变量
      end;
    end;//将用户设置的输入法赋值给编辑控件
    Procedure TForm2.SetIme;
    var
    i:Integer;
    begin
    for i:=ComponentCount-1 DownTo 0 do
     begin
       if (Components[i] is TEdit) then (Components[i] as TEdit).ImeName:=Form1.MyImes;
       if (Components[i] is TCombobox) then (Components[i] as TCombobox).ImeName:=Form1.MyImes;
     end;
    end;
      

  5.   

    谢谢  belllab(bell),就是DBGRID有BUG,改过后一切正常!