在Delphi盒子上找到了一个控件,但是此Edit控件却不有输入中文。奇怪的是此控件用微软拼音就能输入中文,而用其它的像五笔等输入的就为乱码,请问是怎么回事。此控件地址http://www.delphibox.com/article.asp?articleid=1464麻烦各位看一下,谢谢了

解决方案 »

  1.   

    这是这个控件中的一段代码
    procedure TCustomASEdit.KeyDown(var Key: word; Shift: TShiftState);
    var
      TmpS              : WideString;
      OldCaretPosition  : integer;
    begin
      inherited KeyDown(Key, Shift);  OldCaretPosition := CaretPosition;
      case Key of
        VK_END: CaretPosition := Length(Text);
        VK_HOME: CaretPosition := 0;
        VK_LEFT:
          if ssCtrl in Shift then
            CaretPosition := GetPrivWordBeging(CaretPosition)
          else
            CaretPosition := CaretPosition - 1;
        VK_RIGHT:
          if ssCtrl in Shift then
            CaretPosition := GetNextWordBeging(CaretPosition)
          else
            CaretPosition := CaretPosition + 1;
        VK_DELETE, 8:                       //删除和回退按键
          if not ReadOnly then
          begin
            if SelLength <> 0 then
            begin
              if Shift = [ssShift] then
                CutToClipboard
              else
                ClearSelection;
            end
            else
            begin
              TmpS := Text;
              if TmpS <> '' then
                if Key = VK_DELETE then
                begin
                  FActionStack.FragmentDeleted(CaretPosition + 1, TmpS[CaretPosition
                    + 1]);
                  Delete(TmpS, CaretPosition + 1, 1);
                end
                else
                begin                       {回退}
                  if CaretPosition > 0 then
                    FActionStack.FragmentDeleted(CaretPosition,
                      TmpS[CaretPosition]);
                  Delete(TmpS, CaretPosition, 1);
                  CaretPosition := CaretPosition - 1;
                end;
              Text := TmpS;
            end;
          end;
        VK_INSERT:
          if Shift = [ssCtrl] then
            CopyToClipboard
          else
            if Shift = [ssShift] then
              PasteFromClipboard;
        Ord('c'),
          Ord('C'):
          if Shift = [ssCtrl] then
            CopyToClipboard;
        Ord('v'),
          Ord('V'):
          if Shift = [ssCtrl] then
            PasteFromClipboard;
        Ord('x'),
          Ord('X'):
          if Shift = [ssCtrl] then
            CutToClipboard;
        Ord('z'), Ord('Z'):
          if Shift = [ssCtrl] then
            UnDo;
      end;  if Key in [VK_END, VK_HOME, VK_LEFT, VK_RIGHT] then
      begin
        if ssShift in Shift then
        begin
          if SelLength = 0 then
            FSelStart := OldCaretPosition;
          FSelStart := CaretPosition;
          FSelLength := FSelLength - (CaretPosition - OldCaretPosition);
        end
        else
          FSelLength := 0;
        Invalidate;
      end;
      UpdateCaretePosition;
    end;
    procedure TCustomASEdit.KeyPress(var Key: Char);
    begin
      inherited KeyPress(Key);  if (Ord(Key) >= 32) and not ReadOnly then
        InsertChar(WideChar(Key));
    end;
    procedure TCustomASEdit.InsertChar(Ch: WideChar);
    begin
      if ReadOnly then
        Exit;  InsertText(Ch);
    end;
    procedure TCustomASEdit.InsertText(AText: WideString);
    var
      TmpS              : WideString;
    begin
      if ReadOnly then
        Exit;  TmpS := Text;
      FActionStack.FragmentDeleted(SelStart + 1, Copy(TmpS, SelStart + 1,
        SelLength));
      Delete(TmpS, SelStart + 1, SelLength);
      FActionStack.FragmentInserted(SelStart + 1, Length(AText), SelLength <> 0);
      Insert(AText, TmpS, SelStart + 1);
      if (MaxLength <= 0) or (Length(TmpS) <= MaxLength) then
      begin
        Text := TmpS;
        CaretPosition := SelStart + Length(AText);
      end;
      SelLength := 0;
    end;
      

  2.   

    唉,苦呀我经过试验发现在KeyPress事件中,将收到的Key记录下来时,用WideChar做转换是会造成中文字变成乱码,但不用也是乱码,这是怎么回事呀