Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning an ADOrecorset from an ActiveX Server Object

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
NL
Hello,

I have a problem returning an ADOrecorset from an ActiveX Server Object.

I have an MS SQL server database with a table Students.

I have an ActiveX Library named “ApplicationLIB”. To this ActiveX Library I added "Microsft ActiveX Data Objects 2.7 Library" on the uses tab.

In this library there is an Active Server Object called “Students”. To this object I added an method called “getStudents” with a parameter “students” type “_recordset**” modifier “out”. To the body of this method I added the following code:

procedure TStudents.getStudents(out students: _Recordset);
var db : connection;
begin
db.Open('driver={SQL Server};server=Mobile2;database=DB2',
'saGast','saGast',0);
students := db.execute('select * from students',eoAsyncExecute );
db.Close();
end;


When I Build this project I get the following errors:

“(main.pas line 16) Declaration of ‘getStudents’ differs from declaration in interface ‘IStudents’”

and

“(main.pas line 37) Types of actual and formal var parameters must be identical”



Please can anyone help me, I can’t figure it out, declarations are everywhere the same….!!!???

Thanks in advance,

Charl



Here is all code I have written for this project:
And I have an ASP page that calls this Active Server Object. The .ASP page looks like this (StudentsASP.asp):



<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject(&quot;ApplicationLIB.Students&quot;)
dim data
DelphiASPObj.getStudents(data)
do while not data.eof
response.write(data(&quot;name&quot;))%>
<br><%
data.movenext
loop
%>
<HR>
</BODY>
</HTML>



The whole code from “ApplicationLIB.dpr”:


library ApplicationLIB;

{%File 'StudentsASP.asp'}

uses
ComServ,
ApplicationLIB_TLB in 'ApplicationLIB_TLB.pas',
main in 'main.pas' {Students: CoClass};

exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;

{$R *.TLB}

{$R *.RES}

begin
end.



The whole code from “main.pas”:


unit main;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AspTlb, ApplicationLIB_TLB, StdVcl, ADODB_TLB, ADOdb;

type
TStudents = class(TASPObject, IStudents)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure getStudents(out students: _Recordset); safecall;
end;

implementation

uses ComServ;

procedure TStudents.OnEndPage;
begin
inherited OnEndPage;
end;

procedure TStudents.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;

procedure TStudents.getStudents(out students: _Recordset);
var db : connection;
begin
db.Open('driver={SQL Server};server=Mobile2;database=DB2',
'saGast','saGast',0);
students := db.execute('select * from students',eoAsyncExecute );
db.Close();
end;

initialization
TAutoObjectFactory.Create(ComServer, TStudents, Class_Students,
ciMultiInstance, tmApartment);
end.



The whole code from “ApplicationLIB_TLB.pas”:


unit ApplicationLIB_TLB;

// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //

// PASTLWTR : $Revision: 1.130 $
// File generated on 18-09-2003 0:17:01 from Type Library described below.

// ************************************************************************ //
// Type Lib: C:\Charl\school\HSBOS\SE3\ASPAPP\ApplicationLIB.tlb (1)
// LIBID: {6E117C1D-6389-4B23-AC49-10D683E5F540}
// LCID: 0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (C:\WINDOWS\System32\stdole2.tlb)
// (2) v4.0 StdVCL, (C:\WINDOWS\System32\stdvcl40.dll)
// (3) v2.7 ADODB, (C:\Program Files\Common Files\system\ado\msado15.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}

interface

uses ActiveX, ADODB_TLB, Classes, Graphics, StdVCL, Variants, Windows;



// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
ApplicationLIBMajorVersion = 1;
ApplicationLIBMinorVersion = 0;

LIBID_ApplicationLIB: TGUID = '{6E117C1D-6389-4B23-AC49-10D683E5F540}';

IID_IStudents: TGUID = '{890535B4-C26E-481A-9E3A-9DE45F994298}';
CLASS_Students: TGUID = '{3AC9994A-7456-41A1-9F58-986FE5BB3B39}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IStudents = interface;
IStudentsDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
Students = IStudents;


// *********************************************************************//
// Interface: IStudents
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {890535B4-C26E-481A-9E3A-9DE45F994298}
// *********************************************************************//
IStudents = interface(IDispatch)
['{890535B4-C26E-481A-9E3A-9DE45F994298}']
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure OnEndPage; safecall;
procedure getStudents(out students: _Recordset); safecall;
end;

// *********************************************************************//
// DispIntf: IStudentsDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {890535B4-C26E-481A-9E3A-9DE45F994298}
// *********************************************************************//
IStudentsDisp = dispinterface
['{890535B4-C26E-481A-9E3A-9DE45F994298}']
procedure OnStartPage(const AScriptingContext: IUnknown); dispid 1;
procedure OnEndPage; dispid 2;
procedure getStudents(out students: _Recordset); dispid 3;
end;

// *********************************************************************//
// The Class CoStudents provides a Create and CreateRemote method to
// create instances of the default interface IStudents exposed by
// the CoClass Students. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoStudents = class
class function Create: IStudents;
class function CreateRemote(const MachineName: string): IStudents;
end;

implementation

uses ComObj;

class function CoStudents.Create: IStudents;
begin
Result := CreateComObject(CLASS_Students) as IStudents;
end;

class function CoStudents.CreateRemote(const MachineName: string): IStudents;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Students) as IStudents;
end;

end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top