服务器端:
unit PDynamicSQLDemo_TLB;
{$TYPEDADDRESS OFF}
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL,
MIDAS;
// *********************************************************************//
// 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
PDynamicSQLDemoMajorVersion = 1;
PDynamicSQLDemoMinorVersion = 0;
LIBID_PDynamicSQLDemo: TGUID = '{8C16E961-5515-11D3-8FB9-0080C88AAA0D}';
IID_IDynamicSQLDemoServer: TGUID = '{8C16E962-5515-11D3-8FB9-0080C88AAA0D}';
CLASS_DynamicSQLDemoServer: TGUID = '{8C16E964-5515-11D3-8FB9-0080C88AAA0D}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IDynamicSQLDemoServer = interface;
IDynamicSQLDemoServerDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
DynamicSQLDemoServer = IDynamicSQLDemoServer;
// *********************************************************************//
// Interface: IDynamicSQLDemoServer
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {8C16E962-5515-11D3-8FB9-0080C88AAA0D}
// *********************************************************************//
IDynamicSQLDemoServer = interface(IAppServer)
['{8C16E962-5515-11D3-8FB9-0080C88AAA0D}']
procedure GetAllTables(var vTables: OleVariant);
safecall;
end;
// *********************************************************************//
// DispIntf: IDynamicSQLDemoServerDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {8C16E962-5515-11D3-8FB9-0080C88AAA0D}
// *********************************************************************//
IDynamicSQLDemoServerDisp = dispinterface
['{8C16E962-5515-11D3-8FB9-0080C88AAA0D}']
procedure GetAllTables(var vTables: OleVariant);
dispid 1;
function AS_ApplyUpdates(const ProviderName: WideString;
Delta: OleVariant;
MaxErrors: Integer;
out ErrorCount: Integer;
var OwnerData: OleVariant): OleVariant;
dispid 20000000;
function AS_GetRecords(const ProviderName: WideString;
Count: Integer;
out RecsOut: Integer;
Options: Integer;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant): OleVariant;
dispid 20000001;
function AS_DataRequest(const ProviderName: WideString;
Data: OleVariant): OleVariant;
dispid 20000002;
function AS_GetProviderNames: OleVariant;
dispid 20000003;
function AS_GetParams(const ProviderName: WideString;
var OwnerData: OleVariant): OleVariant;
dispid 20000004;
function AS_RowRequest(const ProviderName: WideString;
Row: OleVariant;
RequestType: Integer;
var OwnerData: OleVariant): OleVariant;
dispid 20000005;
procedure AS_Execute(const ProviderName: WideString;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant);
dispid 20000006;
end;
// *********************************************************************//
// The Class CoDynamicSQLDemoServer provides a Create and CreateRemote method to
// create instances of the default interface IDynamicSQLDemoServer exposed by
// the CoClass DynamicSQLDemoServer. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoDynamicSQLDemoServer = class
class function Create: IDynamicSQLDemoServer;
class function CreateRemote(const MachineName: string): IDynamicSQLDemoServer;
end;
// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TDynamicSQLDemoServer
// Help String : DynamicSQLDemoServer Object
// Default Interface: IDynamicSQLDemoServer
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TDynamicSQLDemoServerProperties= class;
{$ENDIF}
TDynamicSQLDemoServer = class(TOleServer)
private
FIntf: IDynamicSQLDemoServer;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TDynamicSQLDemoServerProperties;
function GetServerProperties: TDynamicSQLDemoServerProperties;
{$ENDIF}
function GetDefaultInterface: IDynamicSQLDemoServer;
protected
procedure InitServerData;
override;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure Connect;
override;
procedure ConnectTo(svrIntf: IDynamicSQLDemoServer);
procedure Disconnect;
override;
function AS_ApplyUpdates(const ProviderName: WideString;
Delta: OleVariant;
MaxErrors: Integer;
out ErrorCount: Integer;
var OwnerData: OleVariant): OleVariant;
function AS_GetRecords(const ProviderName: WideString;
Count: Integer;
out RecsOut: Integer;
Options: Integer;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant): OleVariant;
function AS_DataRequest(const ProviderName: WideString;
Data: OleVariant): OleVariant;
function AS_GetProviderNames: OleVariant;
function AS_GetParams(const ProviderName: WideString;
var OwnerData: OleVariant): OleVariant;
function AS_RowRequest(const ProviderName: WideString;
Row: OleVariant;
RequestType: Integer;
var OwnerData: OleVariant): OleVariant;
procedure AS_Execute(const ProviderName: WideString;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant);
procedure GetAllTables(var vTables: OleVariant);
property DefaultInterface: IDynamicSQLDemoServer read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TDynamicSQLDemoServerProperties read GetServerProperties;
{$ENDIF}
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TDynamicSQLDemoServer
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TDynamicSQLDemoServerProperties = class(TPersistent)
private
FServer: TDynamicSQLDemoServer;
function GetDefaultInterface: IDynamicSQLDemoServer;
constructor Create(AServer: TDynamicSQLDemoServer);
protected
public
property DefaultInterface: IDynamicSQLDemoServer read GetDefaultInterface;
published
end;
{$ENDIF}
procedure Register;
implementation
uses ComObj;
class function CoDynamicSQLDemoServer.Create: IDynamicSQLDemoServer;
begin
Result := CreateComObject(CLASS_DynamicSQLDemoServer) as IDynamicSQLDemoServer;
end;
class function CoDynamicSQLDemoServer.CreateRemote(const MachineName: string): IDynamicSQLDemoServer;
begin
Result := CreateRemoteComObject(MachineName, CLASS_DynamicSQLDemoServer) as IDynamicSQLDemoServer;
end;
procedure TDynamicSQLDemoServer.InitServerData;
const
CServerData: TServerData = (
ClassID: '{8C16E964-5515-11D3-8FB9-0080C88AAA0D}';
IntfIID: '{8C16E962-5515-11D3-8FB9-0080C88AAA0D}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;
procedure TDynamicSQLDemoServer.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as IDynamicSQLDemoServer;
end;
end;
procedure TDynamicSQLDemoServer.ConnectTo(svrIntf: IDynamicSQLDemoServer);
begin
Disconnect;
FIntf := svrIntf;
end;
procedure TDynamicSQLDemoServer.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;
function TDynamicSQLDemoServer.GetDefaultInterface: IDynamicSQLDemoServer;
begin
if FIntf = nil then
Connect;
Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
Result := FIntf;
end;
constructor TDynamicSQLDemoServer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TDynamicSQLDemoServerProperties.Create(Self);
{$ENDIF}
end;
destructor TDynamicSQLDemoServer.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TDynamicSQLDemoServer.GetServerProperties: TDynamicSQLDemoServerProperties;
begin
Result := FProps;
end;
{$ENDIF}
function TDynamicSQLDemoServer.AS_ApplyUpdates(const ProviderName: WideString;
Delta: OleVariant;
MaxErrors: Integer;
out ErrorCount: Integer;
var OwnerData: OleVariant): OleVariant;
begin
Result := DefaultInterface.AS_ApplyUpdates(ProviderName, Delta, MaxErrors, ErrorCount, OwnerData);
end;
function TDynamicSQLDemoServer.AS_GetRecords(const ProviderName: WideString;
Count: Integer;
out RecsOut: Integer;
Options: Integer;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant): OleVariant;
begin
Result := DefaultInterface.AS_GetRecords(ProviderName, Count, RecsOut, Options, CommandText,
Params, OwnerData);
end;
function TDynamicSQLDemoServer.AS_DataRequest(const ProviderName: WideString;
Data: OleVariant): OleVariant;
begin
Result := DefaultInterface.AS_DataRequest(ProviderName, Data);
end;
function TDynamicSQLDemoServer.AS_GetProviderNames: OleVariant;
begin
Result := DefaultInterface.AS_GetProviderNames;
end;
function TDynamicSQLDemoServer.AS_GetParams(const ProviderName: WideString;
var OwnerData: OleVariant): OleVariant;
begin
Result := DefaultInterface.AS_GetParams(ProviderName, OwnerData);
end;
function TDynamicSQLDemoServer.AS_RowRequest(const ProviderName: WideString;
Row: OleVariant;
RequestType: Integer;
var OwnerData: OleVariant): OleVariant;
begin
Result := DefaultInterface.AS_RowRequest(ProviderName, Row, RequestType, OwnerData);
end;
procedure TDynamicSQLDemoServer.AS_Execute(const ProviderName: WideString;
const CommandText: WideString;
var Params: OleVariant;
var OwnerData: OleVariant);
begin
DefaultInterface.AS_Execute(ProviderName, CommandText, Params, OwnerData);
end;
procedure TDynamicSQLDemoServer.GetAllTables(var vTables: OleVariant);
begin
DefaultInterface.GetAllTables(vTables);
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TDynamicSQLDemoServerProperties.Create(AServer: TDynamicSQLDemoServer);
begin
inherited Create;
FServer := AServer;
end;
function TDynamicSQLDemoServerProperties.GetDefaultInterface: IDynamicSQLDemoServer;
begin
Result := FServer.DefaultInterface;
end;
{$ENDIF}
procedure Register;
begin
RegisterComponents('Servers',[TDynamicSQLDemoServer]);
end;
end.