Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 6

Chapter 23 - Project ConvertCaller

Project Structure

ConvertCaller.dpr
program ConvertCaller;

uses
  Forms,
  CallerForm in 'CallerForm.pas' {Form1},
  ConvertIntf in 'ConvertIntf.pas';

{$R *.res}

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

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    EditAmount: TEdit;
    ComboBoxFrom: TComboBox;
    ComboBoxTo: TComboBox;
    LabelResult: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Invoker: THTTPRio;
    ConvIntf: IConvert;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  LabelResult.Caption := Format ('%n', [(ConvIntf.ConvertCurrency(
    ComboBoxFrom.Text, ComboBoxTo.Text, StrToFloat (EditAmount.Text)))]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Invoker := THTTPRio.Create(nil);
  Invoker.URL := 'http://localhost/scripts/ConvertService.exe/soap/iconvert';
  ConvIntf := Invoker as IConvert;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  TypeNames: string;
begin
  TypeNames := ConvIntf.TypesList;
  ComboBoxFrom.Items.Text := StringReplace (TypeNames, ';', sLineBreak, [rfReplaceAll]);
  ComboBoxTo.Items := ComboBoxFrom.Items;
end;

end.
ConvertIntf.pas
unit ConvertIntf;

interface

type
  IConvert = interface(IInvokable)
  ['{FF1EAA45-0B94-4630-9A18-E768A91A78E2}']
    function ConvertCurrency (Source, Dest: string; Amount: Double): Double; stdcall;
    function ToEuro (Source: string; Amount: Double): Double; stdcall;
    function FromEuro (Dest: string; Amount: Double): Double; stdcall;
    function TypesList: string; stdcall;
end;

implementation

uses
  InvokeRegistry;

initialization
  InvRegistry.RegisterInterface(TypeInfo(IConvert));
end.
CallerForm.dfm
object Form1: TForm1
  Left = 267
  Top = 123
  Width = 252
  Height = 276
  Caption = 'Convert Caller'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'MS Sans Serif'
  Font.Style = [fsBold]
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 16
  object LabelResult: TLabel
    Left = 40
    Top = 200
    Width = 145
    Height = 16
    Alignment = taCenter
    AutoSize = False
    Caption = '0'
  end
  object Button1: TButton
    Left = 80
    Top = 160
    Width = 75
    Height = 25
    Caption = 'Convert'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 72
    Top = 24
    Width = 75
    Height = 25
    Caption = 'Fill List'
    TabOrder = 1
    OnClick = Button2Click
  end
  object EditAmount: TEdit
    Left = 40
    Top = 128
    Width = 145
    Height = 24
    TabOrder = 2
    Text = '1000'
  end
  object ComboBoxFrom: TComboBox
    Left = 40
    Top = 64
    Width = 145
    Height = 24
    Style = csDropDownList
    ItemHeight = 16
    TabOrder = 3
  end
  object ComboBoxTo: TComboBox
    Left = 40
    Top = 96
    Width = 145
    Height = 24
    Style = csDropDownList
    ItemHeight = 16
    TabOrder = 4
  end
end