我做了,DELETE和UPDATE都行,就是INSERT不行
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project2_TLB, StdVcl, DB, DBTables, Provider,StrUtils,Variants,Unit1;
type
TZJMTUServer = class(TRemoteDataModule, IZJMTUServer)
DataSetProvider1: TDataSetProvider;
Database1: TDatabase;
Query1: TQuery;
UpdateSQL1: TUpdateSQL;
UpdateSQL2: TUpdateSQL;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
procedure DataSetProvider1BeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
procedure SetParams(CUpdateSQL:TUpdateSQL;CDeltaDS: TCustomClientDataSet;CUpdateKind:TUpdateKind);
end;
implementation
{$R *.DFM}
class procedure TZJMTUServer.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;
procedure TZJMTUServer.SetParams(CUpdateSQL:TUpdateSQL;CDeltaDS: TCustomClientDataSet;CUpdateKind:TUpdateKind);
var
i:integer;
PName:string;
Field:TField;
begin
if not assigned(CUpdateSQL.DataSet) then
exit;
with CUpdateSQL.Query[CUpdateKind]do
begin
for i:=0 to Params.Count-1do
begin
PName:=MidStr(Params.Name,5,Length(Params.Name)-4);
Field:=CDeltaDS.FindField(PName);
if not Assigned(Field) then
continue;
Case CUpdateKind of
ukInsert:
begin
Form1.StatusBar1.Panels[1].Text:='Inserting....';
if VarIsEmpty(Field.NewValue) then
Params.AssignFieldValue(Field,Field.CurValue)
else
Params.AssignFieldValue(Field,Field.NewValue);
end;
ukDelete:
begin
Form1.StatusBar1.Panels[2].Text:='Deleteing....';
Params.AssignFieldValue(Field,Field.OldValue);
end;
ukModify:
begin
Form1.StatusBar1.Panels[3].Text:='Updating....';
if MidStr(Params.Name,1,4)='OLD_' then
Params.AssignFieldValue(Field,Field.OldValue)
else
begin
if VarIsEmpty(Field.NewValue) then
Params.AssignFieldValue(Field,Field.OldValue)
else
Params.AssignFieldValue(Field,Field.NewValue);
end;
end;
end;
end;
end;
end;
procedure TZJMTUServer.DataSetProvider1BeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
begin
ClientDataSet1.Data:=DeltaDS.Data;
Form1.StatusBar1.Panels[0].Text:='Start....';
Query1.UpdateObject:=UpdateSQL1;
SetParams(UpdateSQL1,DeltaDS,UpdateKind);
UpdateSQL1.ExecSQL(UpdateKind);
Query1.UpdateObject:=UpdateSQL2;
SetParams(UpdateSQL2,DeltaDS,UpdateKind);
UpdateSQL2.ExecSQL(UpdateKind);
Applied:=true;
end;
initialization
TComponentFactory.Create(ComServer, TZJMTUServer,
Class_ZJMTUServer, ciMultiInstance, tmApartment);
end.
不过在CDeltaDS.DATA有插入的数据,还在苦思当中