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 22 - Project WSnapTable

Project Structure

WSnapTable.dpr
program WSnapTable;

{$APPTYPE GUI}

uses
  Forms,
  ComApp,
  wsnapform in 'wsnapform.pas' {Form1},
  table_dm in 'table_dm.pas' {table: TWebAppPageModule} {*.html},
  wsnapdata in 'wsnapdata.pas' {WebDataModule1: TWebDataModule},
  form_dm in 'form_dm.pas' {formview: TWebPageModule} {*.html};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
wsnapform.pas
unit wsnapform;

interface

uses
  SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses ComApp;

{$R *.DFM}

const
  CLASS_ComWebApp: TGUID = '{80D1D620-FE41-4FD0-BE34-9CB073C0635F}';

initialization
  TWebAppAutoObjectFactory.Create(Class_ComWebApp,
    'WSnapTable', 'WSnapTable Object');

end.
table_dm.pas

unit table_dm;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, WebModu, HTTPProd, ReqMulti,
  WebDisp, WebAdapt, WebComp, CompProd, PagItems, SiteProd, DBXpress,
  FMTBcd, MidItems, WebForm, DB, SqlExpr, DBAdapt, Provider, DBClient;

type
  Ttable = class(TWebAppPageModule)
    AdapterPageProducer: TAdapterPageProducer;
    WebAppComponents: TWebAppComponents;
    ApplicationAdapter: TApplicationAdapter;
    PageDispatcher: TPageDispatcher;
    AdapterDispatcher: TAdapterDispatcher;
    DataSetAdapter1: TDataSetAdapter;
    AdapterForm1: TAdapterForm;
    AdapterGrid1: TAdapterGrid;
    AdapterCommandGroup1: TAdapterCommandGroup;
    CmdPrevPage: TAdapterActionButton;
    CmdGotoPage: TAdapterActionButton;
    CmdNextPage: TAdapterActionButton;
    ColCUST_NO: TAdapterDisplayColumn;
    ColCUSTOMER: TAdapterDisplayColumn;
    ColADDRESS_LINE1: TAdapterDisplayColumn;
    ColCITY: TAdapterDisplayColumn;
    ColSTATE_PROVINCE: TAdapterDisplayColumn;
    ColCOUNTRY: TAdapterDisplayColumn;
    AdapterCommandColumn1: TAdapterCommandColumn;
    CmdEditRow: TAdapterActionButton;
    CmdDeleteRow: TAdapterActionButton;
    AdapterCommandGroup2: TAdapterCommandGroup;
    CmdNewRow: TAdapterActionButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function table: Ttable;

implementation

{$R *.dfm}  {*.html}

uses WebReq, WebCntxt, WebFact, Variants, wsnapdata;

function table: Ttable;
begin
  Result := Ttable(WebContext.FindModuleClass(Ttable));
end;

initialization
  if WebRequestHandler <> nil then
    WebRequestHandler.AddWebModuleFactory(TWebAppPageModuleFactory.Create(Ttable, TWebPageInfo.Create([wpPublished {, wpLoginRequired}], '.html'), caCache));

end.
wsnapdata.pas

unit wsnapdata;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, WebModu, DBXpress, FMTBcd,
  Provider, SqlExpr, DB, DBClient;

type
  TWebDataModule1 = class(TWebDataModule)
    ClientDataSet1: TClientDataSet;
    SQLConnection1: TSQLConnection;
    SQLDataSet1: TSQLDataSet;
    DataSetProvider1: TDataSetProvider;
    procedure ClientDataSet1AfterPost(DataSet: TDataSet);
    procedure ClientDataSet1AfterDelete(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function WebDataModule1: TWebDataModule1;

implementation

{$R *.dfm}

 uses WebReq, WebCntxt, WebFact, Variants;

function WebDataModule1: TWebDataModule1;
begin
  Result := TWebDataModule1(WebContext.FindModuleClass(TWebDataModule1));
end;

procedure TWebDataModule1.ClientDataSet1AfterPost(DataSet: TDataSet);
begin
  ClientDataSet1.ApplyUpdates(-1);
end;

procedure TWebDataModule1.ClientDataSet1AfterDelete(DataSet: TDataSet);
begin
  ClientDataSet1.ApplyUpdates(-1);
end;

initialization
  if WebRequestHandler <> nil then
    WebRequestHandler.AddWebModuleFactory(TWebDataModuleFactory.Create(TWebDataModule1, crAlways, caCache));

end.
form_dm.pas

unit form_dm;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, WebModu, HTTPProd,
  CompProd, PagItems, SiteProd, MidItems, WebForm, WebComp;

type
  Tformview = class(TWebPageModule)
    AdapterPageProducer: TAdapterPageProducer;
    AdapterForm1: TAdapterForm;
    AdapterFieldGroup1: TAdapterFieldGroup;
    AdapterCommandGroup1: TAdapterCommandGroup;
    CmdDeleteRow: TAdapterActionButton;
    CmdCancel: TAdapterActionButton;
    CmdApply: TAdapterActionButton;
    FldCUST_NO: TAdapterDisplayField;
    FldCUSTOMER: TAdapterDisplayField;
    FldADDRESS_LINE1: TAdapterDisplayField;
    FldCITY: TAdapterDisplayField;
    FldSTATE_PROVINCE: TAdapterDisplayField;
    FldCOUNTRY: TAdapterDisplayField;
    AdapterErrorList1: TAdapterErrorList;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function formview: Tformview;

implementation

{$R *.dfm}  {*.html}

uses WebReq, WebCntxt, WebFact, Variants, table_dm;

function formview: Tformview;
begin
  Result := Tformview(WebContext.FindModuleClass(Tformview));
end;

initialization
  if WebRequestHandler <> nil then
    WebRequestHandler.AddWebModuleFactory(TWebPageModuleFactory.Create(Tformview, TWebPageInfo.Create([{wpPublished, wpLoginRequired}], '.html'), crOnDemand, caCache));

end.
wsnapform.dfm
object Form1: TForm1
  Left = 133
  Top = 120
  Width = 222
  Height = 155
  Caption = 'WSnapTable'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
end
table_dm.dfm
object table: Ttable
  OldCreateOrder = False
  PageProducer = AdapterPageProducer
  AppServices = WebAppComponents
  Left = 524
  Top = 183
  Height = 296
  Width = 241
  object AdapterPageProducer: TAdapterPageProducer
    HTMLDoc.Strings = (
      '<html>'
      '<head>'
      '</head>'
      '<body>'
      '<#STYLES><#WARNINGS><#SERVERSCRIPT>'
      '</body>'
      '</html>')
    Left = 48
    Top = 8
    object AdapterForm1: TAdapterForm
      object AdapterCommandGroup1: TAdapterCommandGroup
        DisplayComponent = AdapterGrid1
        object CmdPrevPage: TAdapterActionButton
          ActionName = 'PrevPage'
          Caption = 'Previous Page'
        end
        object CmdGotoPage: TAdapterActionButton
          ActionName = 'GotoPage'
        end
        object CmdNextPage: TAdapterActionButton
          ActionName = 'NextPage'
          Caption = 'Next Page'
        end
      end
      object AdapterGrid1: TAdapterGrid
        TableAttributes.CellSpacing = 0
        TableAttributes.CellPadding = 3
        Adapter = DataSetAdapter1
        AdapterMode = 'Browse'
        object ColCUST_NO: TAdapterDisplayColumn
          FieldName = 'CUST_NO'
        end
        object ColCUSTOMER: TAdapterDisplayColumn
          FieldName = 'CUSTOMER'
        end
        object ColADDRESS_LINE1: TAdapterDisplayColumn
          FieldName = 'ADDRESS_LINE1'
        end
        object ColCITY: TAdapterDisplayColumn
          FieldName = 'CITY'
        end
        object ColSTATE_PROVINCE: TAdapterDisplayColumn
          FieldName = 'STATE_PROVINCE'
        end
        object ColCOUNTRY: TAdapterDisplayColumn
          FieldName = 'COUNTRY'
        end
        object AdapterCommandColumn1: TAdapterCommandColumn
          Caption = 'COMMANDS'
          object CmdEditRow: TAdapterActionButton
            ActionName = 'EditRow'
            Caption = 'Edit'
            PageName = 'formview'
            DisplayType = ctAnchor
          end
          object CmdDeleteRow: TAdapterActionButton
            ActionName = 'DeleteRow'
            Caption = 'Delete'
            DisplayType = ctAnchor
          end
        end
      end
      object AdapterCommandGroup2: TAdapterCommandGroup
        DisplayComponent = AdapterGrid1
        object CmdNewRow: TAdapterActionButton
          ActionName = 'NewRow'
          Caption = 'New'
          PageName = 'formview'
        end
      end
    end
  end
  object WebAppComponents: TWebAppComponents
    PageDispatcher = PageDispatcher
    AdapterDispatcher = AdapterDispatcher
    ApplicationAdapter = ApplicationAdapter
    Left = 48
    Top = 56
  end
  object ApplicationAdapter: TApplicationAdapter
    ApplicationTitle = 'WSnapTable'
    Left = 48
    Top = 104
    object TAdapterDefaultActions
    end
    object TAdapterDefaultFields
    end
  end
  object PageDispatcher: TPageDispatcher
    Left = 48
    Top = 152
  end
  object AdapterDispatcher: TAdapterDispatcher
    Left = 48
    Top = 200
  end
  object DataSetAdapter1: TDataSetAdapter
    DataSet = WebDataModule1.ClientDataSet1
    PageSize = 6
    Left = 144
    Top = 16
    object TAdapterDefaultActions
    end
    object TAdapterDefaultFields
    end
  end
end
wsnapdata.dfm
object WebDataModule1: TWebDataModule1
  OldCreateOrder = False
  Left = 500
  Top = 109
  Height = 283
  Width = 235
  object ClientDataSet1: TClientDataSet
    Active = True
    Aggregates = <>
    AggregatesActive = True
    Params = <>
    ProviderName = 'DataSetProvider1'
    AfterPost = ClientDataSet1AfterPost
    AfterDelete = ClientDataSet1AfterDelete
    Left = 64
    Top = 32
  end
  object SQLConnection1: TSQLConnection
    Connected = True
    ConnectionName = 'IBLocal'
    DriverName = 'Interbase'
    GetDriverFunc = 'getSQLDriverINTERBASE'
    LibraryName = 'dbexpint.dll'
    LoginPrompt = False
    Params.Strings = (
      'BlobSize=-1'
      'CommitRetain=False'

              'Database=c:\program files\interbase corp\interbase6\examples\dat' +
        'abase\employee.gdb'
      'DriverName=Interbase'
      'Password=masterkey'
      'RoleName=RoleName'
      'ServerCharSet=ASCII'
      'SQLDialect=1'
      'Interbase TransIsolation=ReadCommited'
      'User_Name=sysdba'
      'WaitOnLocks=True')
    VendorLib = 'GDS32.DLL'
    Left = 64
    Top = 168
  end
  object SQLDataSet1: TSQLDataSet
    SQLConnection = SQLConnection1
    CommandText =
       'select CUST_NO, CUSTOMER, ADDRESS_LINE1, CITY, STATE_PROVINCE, C' +
      'OUNTRY from CUSTOMER'
    Params = <>
    Left = 64
    Top = 120
  end
  object DataSetProvider1: TDataSetProvider
    DataSet = SQLDataSet1
    Constraints = True
    Left = 64
    Top = 80
  end
end
form_dm.dfm
object formview: Tformview
  OldCreateOrder = False
  PageProducer = AdapterPageProducer
  Left = 297
  Top = 213
  Height = 150
  Width = 215
  object AdapterPageProducer: TAdapterPageProducer
    HTMLDoc.Strings = (
      '<html>'
      '<head>'
      '</head>'
      '<body>'
      '<#STYLES><#WARNINGS><#SERVERSCRIPT>'
      '</body>'
      '</html>')
    Left = 48
    Top = 8
    object AdapterForm1: TAdapterForm
      object AdapterErrorList1: TAdapterErrorList
        Adapter = table.DataSetAdapter1
      end
      object AdapterCommandGroup1: TAdapterCommandGroup
        DisplayComponent = AdapterFieldGroup1
        object CmdApply: TAdapterActionButton
          ActionName = 'Apply'
          PageName = 'table'
        end
        object CmdCancel: TAdapterActionButton
          ActionName = 'Cancel'
          PageName = 'table'
        end
        object CmdDeleteRow: TAdapterActionButton
          ActionName = 'DeleteRow'
          Caption = 'Delete'
          PageName = 'table'
        end
      end
      object AdapterFieldGroup1: TAdapterFieldGroup
        Adapter = table.DataSetAdapter1
        AdapterMode = 'Edit'
        object FldCUST_NO: TAdapterDisplayField
          DisplayWidth = 10
          FieldName = 'CUST_NO'
        end
        object FldCUSTOMER: TAdapterDisplayField
          DisplayWidth = 27
          FieldName = 'CUSTOMER'
        end
        object FldADDRESS_LINE1: TAdapterDisplayField
          DisplayWidth = 32
          FieldName = 'ADDRESS_LINE1'
        end
        object FldCITY: TAdapterDisplayField
          DisplayWidth = 27
          FieldName = 'CITY'
        end
        object FldSTATE_PROVINCE: TAdapterDisplayField
          DisplayWidth = 17
          FieldName = 'STATE_PROVINCE'
        end
        object FldCOUNTRY: TAdapterDisplayField
          DisplayWidth = 17
          FieldName = 'COUNTRY'
        end
      end
    end
  end
end