小弟剛開始玩三層,請各位老大看看,下面代碼有什麼問題,客戶端用了 ClientDataSet.ApplyUpdate(0),為什麼無法更新數據,
unit Unit2;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, DB, DBTables, Provider,Variants ,Dialogs;type
TTMul008 = class(TRemoteDataModule, ITMul008)
Database1: TDatabase;
Q: TQuery;
DSP: TDataSetProvider;
US_Orders: TUpdateSQL;
procedure DSPBeforeUpdateRecord(Sender: TObject; SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind;
var Applied: Boolean);
private
{ Private declarations }
Procedure SetParams(FUpdateSQL : TUpdateSQL ; DeltaDS : TCustomClientDataSet ;
UpdateKind : TUpdateKind ) ;
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
public
{ Public declarations }
end;implementation{$R *.DFM}class procedure TTMul008.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 TTMul008.DSPBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind; var Applied: Boolean);
begin
Q.UpdateObject := US_Orders ;
SetParams(US_Orders,DeltaDS,UpdateKind) ;
US_Orders.Apply(UpdateKind); Applied := true ;
end;procedure TTMul008.SetParams(FUpdateSQL: TUpdateSQL;
DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind);
var i : integer ;
value : Variant ;
Param : TParam ;
Field : TField ;
Old : Boolean ;
PName : string ;
begin
if Not Assigned(FUpdateSQL.DataSet) then
begin
Exit ;
end ; with FUpdateSQL.Query[UpdateKind] do
begin
for i := 0 to Params.Count - 1 do
begin
Param := Params[i] ;
PName := Param.Name ;
Old := CompareText(Copy(PName,1,4),'Old_') = 0 ;
if Old = true then
begin
System.Delete(PName,1,4) ;
end ;
Field := DeltaDS.FindField(PName) ;
if Not Assigned(Field) then
begin
Continue ;
end ; if Old = true then
begin
Param.AssignFieldValue(Field,Field.NewValue );
end
else
begin
Value := Field.NewValue ;
if VarIsEmpty(Value) then
begin
Value := Field.OldValue ;
end ;
Param.AssignFieldValue(Field,Value);
end;
end ;
end ;
end;initialization
TComponentFactory.Create(ComServer, TTMul008,
Class_TMul008, ciMultiInstance, tmApartment);
end.
unit Unit2;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, DB, DBTables, Provider,Variants ,Dialogs;type
TTMul008 = class(TRemoteDataModule, ITMul008)
Database1: TDatabase;
Q: TQuery;
DSP: TDataSetProvider;
US_Orders: TUpdateSQL;
procedure DSPBeforeUpdateRecord(Sender: TObject; SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind;
var Applied: Boolean);
private
{ Private declarations }
Procedure SetParams(FUpdateSQL : TUpdateSQL ; DeltaDS : TCustomClientDataSet ;
UpdateKind : TUpdateKind ) ;
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
public
{ Public declarations }
end;implementation{$R *.DFM}class procedure TTMul008.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 TTMul008.DSPBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind; var Applied: Boolean);
begin
Q.UpdateObject := US_Orders ;
SetParams(US_Orders,DeltaDS,UpdateKind) ;
US_Orders.Apply(UpdateKind); Applied := true ;
end;procedure TTMul008.SetParams(FUpdateSQL: TUpdateSQL;
DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind);
var i : integer ;
value : Variant ;
Param : TParam ;
Field : TField ;
Old : Boolean ;
PName : string ;
begin
if Not Assigned(FUpdateSQL.DataSet) then
begin
Exit ;
end ; with FUpdateSQL.Query[UpdateKind] do
begin
for i := 0 to Params.Count - 1 do
begin
Param := Params[i] ;
PName := Param.Name ;
Old := CompareText(Copy(PName,1,4),'Old_') = 0 ;
if Old = true then
begin
System.Delete(PName,1,4) ;
end ;
Field := DeltaDS.FindField(PName) ;
if Not Assigned(Field) then
begin
Continue ;
end ; if Old = true then
begin
Param.AssignFieldValue(Field,Field.NewValue );
end
else
begin
Value := Field.NewValue ;
if VarIsEmpty(Value) then
begin
Value := Field.OldValue ;
end ;
Param.AssignFieldValue(Field,Value);
end;
end ;
end ;
end;initialization
TComponentFactory.Create(ComServer, TTMul008,
Class_TMul008, ciMultiInstance, tmApartment);
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货