Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco


Home: Code Repository: Mastering Delphi 6

Chapter 23 - Project BabelFish

Project Structure

BabelFish.dpr
program BabelFish;

uses
  Forms,
  BabelForm in 'BabelForm.pas' {Form1},
  BabelIntf in 'BabelIntf.pas';

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
BabelForm.pas
unit BabelForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Rio, SoapHTTPClient;

type
  TForm1 = class(TForm)
    HTTPRIO1: THTTPRIO;
    Button1: TButton;
    EditSource: TEdit;
    EditTarget: TEdit;
    ComboBoxType: TComboBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  Babelintf;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EditTarget.Text := (HTTPRIO1 as BabelFishPortType).
    BabelFish(ComboBoxType.Text, EditSource.Text);
end;

end.
BabelIntf.pas
unit BabelIntf;

interface

uses Types, XSBuiltIns;
type

  BabelFishPortType = interface(IInvokable)
    ['{DF96B8F8-DD8E-43A1-9276-4F821D9EA3FA}']
    function BabelFish(const translationmode: String; const sourcedata: String): String; stdcall;
  end;


implementation

uses InvokeRegistry;

initialization
  InvRegistry.RegisterInterface(TypeInfo(BabelFishPortType), '', '');

end.
BabelForm.dfm
object Form1: TForm1
  Left = 204
  Top = 215
  Width = 664
  Height = 175
  Caption = 'BabelFish'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 40
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Translate'
    TabOrder = 0
    OnClick = Button1Click
  end
  object EditSource: TEdit
    Left = 160
    Top = 32
    Width = 465
    Height = 21
    TabOrder = 1
    Text = 'This is a sample message for an automatic translation'
  end
  object EditTarget: TEdit
    Left = 160
    Top = 72
    Width = 465
    Height = 21
    TabOrder = 2
  end
  object ComboBoxType: TComboBox
    Left = 40
    Top = 72
    Width = 81
    Height = 21
    ItemHeight = 13
    TabOrder = 3
    Text = 'en_it'
    Items.Strings = (
      'en_it'
      'en_fr'
      'en_de'
      'en_pt'
      'en_es')
  end
  object HTTPRIO1: THTTPRIO
    WSDLLocation = 'C:\md6code\23\BabelFish\BabelFishService.xml'
    Service = 'BabelFish'
    Port = 'BabelFishPort'
    HTTPWebNode.Agent = 'Borland SOAP 1.1'
    HTTPWebNode.UseUTF8InHeader = False
    Converter.Options = [soSendMultiRefObj, soTryAllSchema]
    Left = 32
    Top = 24
  end
end