⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clntmain.pas

📁 《Delphi开发人员指南》配书原码
💻 PAS
字号:
unit ClntMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, StdCtrls, ExtCtrls, ComCtrls;

type
  TClientMainForm = class(TForm)
    Splitter1: TSplitter;
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    Label3: TLabel;
    lvClient1: TListView;
    Panel2: TPanel;
    Panel3: TPanel;
    Button1: TButton;
    Button3: TButton;
    Button5: TButton;
    Panel4: TPanel;
    DBGrid2: TDBGrid;
    lvClient2: TListView;
    Label2: TLabel;
    Label4: TLabel;
    Panel5: TPanel;
    Panel6: TPanel;
    Button2: TButton;
    Button4: TButton;
    Button6: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
  public
    procedure AddErrorToClient1(aFieldName, aOldValue, aNewValue, aCurValue,
      aErrorStr: String);
    { This method is called by the TClientDataSet components on ClientDM
      whenever an error occurs when updating data on the server. }
    procedure AddErrorToClient2(aFieldName, aOldValue, aNewValue, aCurValue,
      aErrorStr: String);
    { This method is called by the TClientDataSet components on ClientDM
      whenever an error occurs when updating data on the server. }
  end;

var
  ClientMainForm: TClientMainForm;

implementation

uses ClntDM;

{$R *.DFM}

procedure AddErrorItem(const aFieldName, aOldValue, aNewValue, aCurValue,
  aErrorStr: String; aData: Pointer; aLV: TListView);
{ This method is used to add a TListItem to the TListView, aLV. The items
  added here give an indication of the errors that occur when performing
  updates to the server data. }
var
  NewItem: TListItem;
begin
  NewItem := aLV.Items.Add;
  NewItem.Caption := aFieldName;
  NewItem.SubItems.Add(aOldValue);
  NewItem.SubItems.Add(aNewValue);
  NewItem.SubItems.Add(aCurValue);
  NewItem.SubItems.Add(aErrorStr);
  NewItem.Data := aData;
end;

procedure TClientMainForm.AddErrorToClient1(aFieldName, aOldValue, aNewValue,
  aCurValue, aErrorStr: String);
begin
  AddErrorItem(aFieldName, aOldValue, aNewValue, aCurValue, aErrorStr, nil,
    lvClient1);
end;

procedure TClientMainForm.AddErrorToClient2(aFieldName, aOldValue, aNewValue,
  aCurValue, aErrorStr: String);
begin
  AddErrorItem(aFieldName, aOldValue, aNewValue, aCurValue, aErrorStr, nil,
    lvClient2)
end;

procedure TClientMainForm.Button1Click(Sender: TObject);
begin
  // Connect to the remote application server.
  ClientDM.rsClient1.Connected := True;
  // Open the dataset.
  ClientDM.cdsEmployee1.Active := True;
end;


procedure TClientMainForm.Button2Click(Sender: TObject);
begin
  // Connect to the remote application server.
  ClientDM.rsClient2.Connected := True;
  // Open the dataset.
  ClientDM.cdsEmployee2.Active := True;
end;

procedure TClientMainForm.Button3Click(Sender: TObject);
begin
  // Close the dataset
  ClientDM.cdsEmployee1.Active := False;
  // Disconnect from the remote application server.
  ClientDM.rsClient1.Connected := False;
end;

procedure TClientMainForm.Button4Click(Sender: TObject);
begin
  // Close the dataset
  ClientDM.cdsEmployee2.Active := False;
  // Disconnect from the remote application server.
  ClientDM.rsClient2.Connected := False;
end;

procedure TClientMainForm.Button5Click(Sender: TObject);
begin
  { Update the server with all updated, inserted, and deleted records from
    this client dataset to the provider on the application server. The
    application server with update the database with the changes unless an error
    occurs which will invoke the TClientDataSet.OnReconcileError event. }
    ClientDM.cdsEmployee1.ApplyUpdates(-1);
end;

procedure TClientMainForm.Button6Click(Sender: TObject);
begin
  { Update the server with all updated, inserted, and deleted records from
    this client dataset to the provider on the application server. The
    application server with update the database with the changes unless an error
    occurs which will invoke the TClientDataSet.OnReconcileError event. }
  ClientDM.cdsEmployee2.ApplyUpdates(-1);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -