|
Delphi 6 and Kylix 2 Web Services, by Bob Swart
WSJ Vol 02 Issue 02 - pg.56
Listing 1
{ Invokable interface declaration unit for IRoman }
unit RomanIntf;
interface
uses
Types, XSBuiltIns;
type
IRoman = interface(IInvokable)
['{01304E12-D6DE-46E8-8585-2D3660B7D9CC}']
// Declare your invokable logic here using standard Object Pascal code
// Remember to include a calling convention! (usually stdcall)
function IntToRoman(I: Integer): String; stdcall;
function RomanToInt(R: String): Integer; stdcall;
end;
implementation
uses
InvokeRegistry;
initialization
InvRegistry.RegisterInterface(TypeInfo(IRoman), '', '');
end.
unit RomanIntf.pas
Listing 2
{ Invokable implementation declaration unit for TRoman,
which implements IRoman }
unit RomanImpl;
interface
uses
RomanIntf, InvokeRegistry;
type
TRoman = class(TInvokableClass, IRoman)
public
// Make sure you have your invokable logic implemented in IRoman
// first, then use CodeInsight(tm) to fill in this implementation
// section by pressing Ctrl+Space, marking all the interface
// declarations for IRoman, and pressing Enter.
function IntToRoman(I: Integer): String; stdcall;
function RomanToInt(R: String): Integer; stdcall;
// Once the declarations are inserted here, use ClassCompletion(tm)
// to write the implementation stubs by pressing Ctrl+Shift+C
end;
implementation
{ TRoman }
function TRoman.IntToRoman(I: Integer): String;
begin
end;
function TRoman.RomanToInt(R: String): Integer;
begin
end;
initialization
InvRegistry.RegisterInvokableClass(TRoman);
end.
Unit RomanImpl.pas
Listing 3.
Unit Roman;
interface
uses
Types, XSBuiltIns;
type
IRoman = interface(IInvokable)
['{01304E12-D6DE-46E8-8585-2D3660B7D9CC}']
function IntToRoman(const I: Integer): WideString; stdcall;
function RomanToInt(const R: WideString): Integer; stdcall;
end;
implementation
uses
InvokeRegistry;
initialization
InvRegistry.RegisterInterface(TypeInfo(IRoman), 'urn:RomanIntf-IRoman', '');
end.
Unit Roman.pas
Listing 4
unit MainForm;
interface
uses
SysUtils, Types, Classes, Variants, QGraphics, QControls, QForms, QDialogs,
Rio, SOAPHTTPClient, Roman, QStdCtrls;
type
TForm1 = class(TForm)
HTTPRIO1: THTTPRIO;
Label1: TLabel;
Label2: TLabel;
EditInt: TEdit;
EditRoman: TEdit;
btnIntToRoman: TButton;
BtnRomanToInt: TButton;
procedure btnIntToRomanClick(Sender: TObject);
procedure BtnRomanToIntClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.xfm}
procedure TForm1.btnIntToRomanClick(Sender: TObject);
var
Int: Integer;
begin
Int := StrToIntDef(EditInt.Text,0);
EditRoman.Text :=
(HTTPRIO1 as IRoman).IntToRoman(Int);
end;
procedure TForm1.BtnRomanToIntClick(Sender: TObject);
var
Int: Integer;
begin
Int := (HTTPRIO1 as IRoman).RomanToInt(EditRoman.Text);
EditInt.Text := IntToStr(Int);
end;
end.
Unit MainForm.pas
|