|
A Midas connection in an ISAPI DLL
To use a MIDAS connection in a ISAPI DLL you need to call the function COInitialize().
The CoInitialize function initializes the COM library and applications need that to make a COM library call.
To use this ISAPI you'll need the simple Midas Server example. The MidasConnection.ConnectType property in this example is set to ctSockets
which means that at the side of the Midas Server a SocketServer must be started. This program (scktsrvr.exe) is located in the Delphi\BIN directory.
If you want to use DCOM then simple change this property to ctDCOM.
Further more you'll need to have the DBClient.dll file installed further described in Building a Midas server step by step guide.
For this example I used CGI-Expert to for the ISAPI DLL generation (for download of a shareware version see Delphi Tools and Utilities)
View the project source (.DPR)
View the unit source (.PAS)
Download the complete code (.ZIP)
Generated with HyperDelphi
library project1;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
View-Project Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the DELPHIMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using DELPHIMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
NsapiEng,
main in 'main.pas' {DataModule1: TDataModule};
begin
IsMultiThread := TRUE;
Datamodule1:=TDatamodule1.Create(nil);
end.
|
Generated with HyperDelphi
unit main;
interface
uses
Windows, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MIDASCon, HttpEng, ActiveX, HUtils, Db, DBClient, GenEng, HDBUtils;
type
TDataModule1 = class(TDataModule)
MIDASConnection1: TMIDASConnection;
ClientDataSet1: TClientDataSet;
GeneralHttpEngine1: TGeneralHttpEngine;
HttpDBGrid1: THttpDBGrid;
procedure GeneralHttpEngine1ExecRequest(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DataModule1: TDataModule1;
implementation
{$R *.DFM}
procedure TDataModule1.GeneralHttpEngine1ExecRequest(Sender: TObject);
var
sqlstatement: string;
begin
COInitialize(nil);
try
MidasConnection1.Connected := true;
try
sqlstatement := FormVar('sql','select * from animals');
Clientdataset1.Data := Clientdataset1.Provider.DataRequest(sqlstatement);
Clientdataset1.Open;
Put('<HTML><BODY>');
HttpDBGrid1.Put;
Put('</HTML></BODY>');
finally
MidasConnection1.Connected := false;
end;
finally
COUnInitialize();
end;
end;
end.
|
|
|