Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 6

Chapter 23 - Project DataService

Project Structure

DataService.dpr
program DataService;

{$APPTYPE CONSOLE}

uses
  WebBroker,
  CGIApp,
  DataWm in 'DataWm.pas' {WebModule1: TWebModule},
  DataService_TLB in 'DataService_TLB.pas',
  DataRdm in 'DataRdm.pas' {DataServiceObj: TRemoteDataModule} {DataServiceObj: CoClass};

{$R *.TLB}

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TWebModule1, WebModule1);
  Application.Run;
end.
DataWm.pas
unit DataWm;

interface

uses
  SysUtils, Classes, HTTPApp, DBClient, Provider, DB, DBTables, WSDLPub,
  SOAPPasInv, SOAPHTTPPasInv, SoapHTTPDisp, WebBrokerSOAP;

type
  TWebModule1 = class(TWebModule)
    HTTPSoapDispatcher1: THTTPSoapDispatcher;
    HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker;
    WSDLHTMLPublish1: TWSDLHTMLPublish;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WebModule1: TWebModule1;

type
  TMyProvider = class (TDatasetProvider)
  public
    constructor Create (AnOwner: TComponent); override;
  end;

implementation

{$R *.DFM}

uses
  InvokeRegistry, Midas, DataRdm;

{ TMyProvider }

constructor TMyProvider.Create(AnOwner: TComponent);
begin
  inherited;
  // initialize
//  WebModule1.Table1.Open;
//  DataSet := WebModule1.Table1;
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(IAppServer));
  InvRegistry.RegisterInvokableClass (TDataServiceObj);

end.
DataService_TLB.pas
unit DataService_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 6/6/2001 2:29:06 AM from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\md6code\23\DataService\DataService.tlb (1)
// LIBID: {DAEA8F54-7BDA-4B0E-BA66-A589A545CABE}
// LCID: 0
// Helpfile: 
// DepndLst: 
//   (1) v2.0 stdole, (C:\WINDOWS\System32\stdole2.tlb)
//   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
//   (3) v1.0 Midas, (C:\WINDOWS\System32\midas.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}

interface

uses ActiveX, Classes, Graphics, Midas, 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
  DataServiceMajorVersion = 1;
  DataServiceMinorVersion = 0;

  LIBID_DataService: TGUID = '{DAEA8F54-7BDA-4B0E-BA66-A589A545CABE}';

  IID_IDataServiceObj: TGUID = '{3AB54780-6B56-4D31-8F29-86F69B013FFD}';
  CLASS_DataServiceObj: TGUID = '{8CB4BA13-F15B-4659-972C-46B4E0195AB0}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  IDataServiceObj = interface;
  IDataServiceObjDisp = dispinterface;

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


// *********************************************************************//
// Interface: IDataServiceObj
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {3AB54780-6B56-4D31-8F29-86F69B013FFD}
// *********************************************************************//
  IDataServiceObj = interface(IAppServer)
    ['{3AB54780-6B56-4D31-8F29-86F69B013FFD}']
  end;

// *********************************************************************//
// DispIntf:  IDataServiceObjDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {3AB54780-6B56-4D31-8F29-86F69B013FFD}
// *********************************************************************//
  IDataServiceObjDisp = dispinterface
    ['{3AB54780-6B56-4D31-8F29-86F69B013FFD}']
    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 CoDataServiceObj provides a Create and CreateRemote method to          
// create instances of the default interface IDataServiceObj exposed by              
// the CoClass DataServiceObj. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                            
// *********************************************************************//
  CoDataServiceObj = class
    class function Create: IDataServiceObj;
    class function CreateRemote(const MachineName: string): IDataServiceObj;
  end;

implementation

uses ComObj;

class function CoDataServiceObj.Create: IDataServiceObj;
begin
  Result := CreateComObject(CLASS_DataServiceObj) as IDataServiceObj;
end;

class function CoDataServiceObj.CreateRemote(const MachineName: string): IDataServiceObj;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DataServiceObj) as IDataServiceObj;
end;

end.
DataRdm.pas
unit DataRdm;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
  DBClient, DataService_TLB, StdVcl, Provider, DB, DBTables;

type
  TDataServiceObj = class(TRemoteDataModule, IDataServiceObj)
    Table1: TTable;
    DataSetProvider1: TDataSetProvider;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.DFM}

initialization
  TComponentFactory.Create(ComServer, TDataServiceObj,
    Class_DataServiceObj, ciMultiInstance, tmApartment);
end.
DataWm.dfm
object WebModule1: TWebModule1
  OldCreateOrder = False
  Actions = <>
  Left = 157
  Top = 377
  Height = 240
  Width = 459
  object HTTPSoapDispatcher1: THTTPSoapDispatcher
    Dispatcher = HTTPSoapPascalInvoker1
    WebDispatch.PathInfo = 'soap*'
    Left = 64
    Top = 48
  end
  object HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker
    Converter.Options = [soSendMultiRefObj, soTryAllSchema]
    Left = 160
    Top = 48
  end
  object WSDLHTMLPublish1: TWSDLHTMLPublish
    WebDispatch.MethodType = mtAny
    WebDispatch.PathInfo = 'wsdl*'
    AdminEnabled = False
    Left = 264
    Top = 40
  end
end
DataRdm.dfm
object DataServiceObj: TDataServiceObj
  OldCreateOrder = False
  Left = 510
  Top = 133
  Height = 150
  Width = 215
  object Table1: TTable
    DatabaseName = 'DBDEMOS'
    TableName = 'customer.db'
    Left = 48
    Top = 48
  end
  object DataSetProvider1: TDataSetProvider
    DataSet = Table1
    Constraints = True
    Left = 104
    Top = 56
  end
end