You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

[ |../../../index.htm#lansa/webserviceseng01_0205.htm]
現在地: Webサービス > Webサービスの利用 > チュートリアル 1 - Google 翻訳 API > Web ページを作成して、サーバー・モジュールをテスト

Web ページを作成して、サーバー・モジュールをテスト

GoogleTranslateTestWebPage という名前の新しいWeb ページを作成します。
Initialize イベントが存在しない場合は、これを追加します。
Evtroutine Handling(#Com_owner.Initialize)
 
Endroutine
次のコードを Initialize イベントに追加します。

  • サーバー・モジュールのオブジェクト作成
    Define_Com Class(#GoogleTranslateServerModule.Translate) Name(#Translator)
  • 翻訳されたテキスト、エラー・メッセージ、ステータスを保持する変数
    Define_Com Class(#PRIM_DC.UnicodeString) Name(#TranslatedText)
    Define_Com Class(#PRIM_DC.UnicodeString) Name(#ErrorMessage)
    Define_Com Class(#PRIM_BOLN) Name(#OK)
  • サーバー・モジュールの起動
    #Translator.Execute Sourcetext('This is so cool!')Sourcelanguage('en') Targetlanguage('fr') Translatedtext(#TranslatedText) Ok(#OK) Errormessage(#ErrorMessage)
  • 結果の表示 (OK の場合)、またはエラー・メッセージ (失敗した場合)
    If (#OK)
       #SYS_WEB.Alert Caption('The translated text in French:' + #TranslatedText)
    Else
       #SYS_WEB.Alert Caption('An error has occurred:' + #ErrorMessage)
    Endif
    API キーが正しく設定されていれば、Web ページ実行時、次のように表示されるはずです。

    次は: 翻訳のためのコードを再利用可能パーツにまとめる
    [ |../../../index.htm#lansa/webserviceseng01_0205.htm]
  • No labels