フリガナを取得する

以下のサンプルは Edit1 に入力された日本語のフリガナを Edit2に代入するものです。フリガナ取得は業務アプリを組むときはだいたい必要になるのでコンポーネントにしておくと便利かも知れません。

■ フリガナ取得の例
uses
  Imm;

function GetFurigana(Control: TWinControl) : string;
var
  Imc : HIMC;
  Len : longint;
  S   : string;
begin
  Imc     :=  ImmGetContext(Control.Handle);
  Len     :=  ImmGetCompositionString(Imc, GCS_RESULTREADSTR, nil, 0);
  SetLength(S, Len + 1);
  ImmGetCompositionString(Imc, GCS_RESULTREADSTR, PChar(S), Len + 1);
  ImmReleaseContext(Control.Handle, Imc);
  SetLength(S, Len);
  Result  :=  S;
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  Edit2.Text  :=  GetFurigana(Edit1);
end;

end.