关于IAppServer接口方法AS_ApplyUpdates使用的问题 (150分)

  • 主题发起人 主题发起人 sunshine770517
  • 开始时间 开始时间
S

sunshine770517

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个数据集的更新,要在一个大循环中通过直接使用IAppServer接口中的
AS_ApplyUpdates方法更新一个表,这种取代cds.ApplyUpdate()的方式是否可增加执行效率?
(在D6中)函数原形是这样的:
function AS_ApplyUpdates(const ProviderName: WideString;
Delta: OleVariant;
MaxErrors: Integer;
out ErrorCount:
Integer;
var OwnerData: OleVariant): OleVariant;
safecall;
这些传入参数应怎样提供呢?尤其是参数Delta不知怎样获取,我试着用cds.delta代入
时出错.请各路大侠帮我.

 
对效率影响不大,反而麻烦。
一般只在cds.ApplyUpdates不方便使用时才用它。
 
是不是问题不够清楚?我想改为晚绑定的方法
实际应用是这样子的:
uses MyDef_TLB;
// 远程数据模块类型库
// 下面IDeveDisp接口是在MyDef_TLB中自定义的
cdsTkstzbbArj.Close;
cdsTkstzbbArj.FetchOnDemand := False;
cdsTkstzbbArj.PacketRecords := 5;
// 分段存取
cdsTkstzbbArj.CommandText := 'select zbxh,nr1,stnr,stda from tkstzbb';
cdsTkstzbbArj.Open;
while cdsTkstzbbArj.RecNo < iRecordCountdo
begin
while not cdsTkstzbbArj.Eofdo
begin
cdsTkstzbbArj.Edit;
stmp := cdsTkstzbbArj.Fields[0].Value;
sZbxh := copy(stmp,1,2)+copy(stmp,4,3);
// 去掉指标序号第三位
// 函数GisMain做了一点压缩的动作
if not GisMain(Gkcdm,sZbxh,
cdsTkstzbbArj.FieldByName('nr1').AsString, form1.Frame31.GPath,
cdsTkstzbbArj.FieldByName('stnr'),cdsTkstzbbArj.FieldByName('stda')) then
begin
strlistLog.Add('导入试题'+sZbxh+'时出错');
StatusBar1.Panels[1].Text := '提示信息:导入试题'+sZbxh+'未成功';
end;
cdsTkstzbbArj.Next;
end;
[red] cdsTkstzbbArj.ApplyUpdates(0);
// 现在使用的调用方法
{ IDeveDisp(Idispatch(IApp)).AS_ApplyUpdates('dspTkstzbb'
,cdsTkstzbbArj.Delta,0,iMaxError,EmptyParam);
} // 待修改方法[/red]
Sleep(150);
cdsTkstzbbArj.GetNextPacket;
cdsTkstzbbArj.Next;
// 避免pacakge里最后一条记录被重写
end;
AS_ApplyUpdates中第二个参数传什么呢?


 
调用的方法没错,你的IApp接口变量怎么来的?
 
据我个人经验,调用AS_ApplyUpdate的理由是为了在客户端使用事务,否则没有必要。
以下是我写的一段程序,使用上述方法,使用正常,可供参考:
// 以下三个为全局变量
// gCS: TClientDataSet = nil;
// gCLSID: TGUID;
// gIID: TGUID;
procedure TMainForm.dsSaveExecute(Sender: TObject);
var
iAS: IAppServer;
iErr: integer;
vData: oleVariant;
vResult: oleVariant;
tranEX: ITransactionContextEx;
begin
if gCS = nil then
exit;
if gCS.State <> dsBrowse then
gCS.Post;
if gCS.ChangeCount <= 0 then
exit;
tranEx := CreateTransactionContextEx;
Try
olecheck(tranEX.createinstance(gCLSID, gIID, iAS));
vResult := iAS.AS_ApplyUpdates(gCS.ProviderName, gCS.Delta, 0, iErr, vData);
except
tranEX.abort;
Raise;
end;
tranEX.Commit;
gCS.MergeChangeLog;
end;
 
to xeen:
首先uses Midas,定义IApp: IAppServer;最后直接使用它
考虑到IAppServer接口也要从Server端传过来,所以这样用,
替换掉cdsTkstzbbArj所连接的dcom.AppServer方法
使用时,第二个参数cdsTkstzbbArj.delta总是为空
如果直接使用cdsTkstzbbArj.ApplyUpdate()时delta就有值
ApplyUpdate()调用之前有准备数据的动作,我不知怎样做
还请说得详细点
 
to maizesdgdcn:
调用cds.ApplyUpdate方法不是已经隐性的使用事务了吗?
gCS.Delta中已经有了要更新的数据么?
 
IApp := Dcomconnection.Appserver as IAppServer;
是这样用的吗?
 
这二天没上DFW,问题已解决
省了约30%的时间,在我这也就省了一个半小时
多谢各位啦:)
 
后退
顶部