We
declared a variable of type Variant
in the main form to hold the COM server. Delphi supports
Variant
s purely in order to support COM, although
they go somewhat against the grain in Delphi programming where the
type of every variable is specified. The Delphi code to instantiate
the server is as follows:
procedure TfrmMain.FormCreate(Sender: TObject); begin try BookServer := CreateOleObject('Doubletalk.BookServer'); StatusBar1.SimpleText := 'BookServer running'; except MessageDlg( 'An instance of the "Doubletalk.BookServer" COM class ' + 'could not be created. Make sure that the BookServer application ' + 'has been registered using a command line. If you have modified ' + 'the source of the server, make very sure all public methods and '+ 'attributes are spelled correctly', mtError, [mbOk], 0); Application.Terminate; end; end;
As with Visual Basic, one line does the work.
Delphi does exactly as good a job as
VB as far as passing simple arguments is concerned. The following
example, behind the File → Open menu item, shows how to call
methods of the BookSet
with integer and string
arguments:
procedure TfrmMain.Open1Click(Sender: TObject); {prompt for a filename and ask BookSet to load it} var trancount: integer; filename: string; begin if OpenDialog1.Execute then begin filename := OpenDialog1.FileName; BookServer.load(OpenDialog1.FileName); trancount := BookServer.Count; StatusBar1.SimpleText := Format('Loaded file %s, %d transactions', ...
No credit card required