在编辑货品资料时,输入货品名后,如何自动产生对应助记码,生成的助记码,可以是拼音码,也可以是五笔.

解决方案 »

  1.   

    function StrToGBC(mChar: WideChar): Integer; { 返回汉字所对应的区位码 }
    begin
      Result := 0;
      if Length(string(mChar)) = 2 then
        if [string(mChar)[1], string(mChar)[2]] <= [#161..#254] then
          Result := (Ord(string(mChar)[1]) - 161 + 1) * 100 +
            Ord(string(mChar)[2]) - 161 + 1;
    end; { StrToGBC }function WideCharToShort(mWideChar: WideChar): Char; { 返回单个汉字的拼音简码 }
    begin
      case StrToGBC(mWideChar) of
        1601..1636: Result := 'A';
        1637..1832: Result := 'B';
        1833..2078: Result := 'C';
        2079..2273: Result := 'D';
        2274..2301: Result := 'E';
        2302..2432: Result := 'F';
        2433..2593: Result := 'G';
        2594..2786: Result := 'H';
        2787..3105: Result := 'J';
        3106..3211: Result := 'K';
        3212..3471: Result := 'L';
        3472..3634: Result := 'M';
        3635..3721: Result := 'N';
        3722..3729: Result := 'O';
        3730..3857: Result := 'P';
        3858..4026: Result := 'Q';
        4027..4085: Result := 'R';
        4086..4389: Result := 'S';
        4390..4557: Result := 'T';
        4558..4683: Result := 'W';
        4694..4924: Result := 'X';
        4925..5248: Result := 'Y';
        5249..5589: Result := 'Z';
      else Result := '_';
      end;
    end; { WideCharToShort }function WideStringToShort(mWideString: WideString): string; { 将字符串转换成简码返回 }
    var
      I: Integer;
    begin
      Result := '';
      for I := 1 to Length(mWideString) do
        if Length(string(mWideString[I])) = 2 then
          Result := Result + WideCharToShort(mWideString[I])
        else Result := Result + mWideString[I];
    end; { WideStringToShort }procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit2.Text := WideStringToShort(Edit1.Text);
    end;
      

  2.   

    codehunter008,你有什么好主意,仔细说一下,谢谢。