那么是哪个事件,是BeforeUpdateRecord事件?
如果是,试试下面的代码
procedure TAutoIncMDForm.DataSetProvider1BeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
begin
if (UpdateKind = ukInsert) and (SourceDS = qryMain)//qryMain是主表名称
begin
//你主表生成主键的代码
//GetCode是生成主键的自定义函数
// FMainCode是RemoteDatamodule的私有变量
FMainCode:==GetCode;
DeltaDS.FieldByName('ID').NewValue:=FMainCode;
end;
// FMainCode是RemoteDatamodule的私有变量
if (UpdateKind = ukInsert) and (SourceDS = qryDetail) and //qryDetail是从表的名称
(DeltaDS.FieldByName('MasterID').Value = Unassigned)
then
then
begin
DeltaDS.FieldByName('MasterID').NewValue := FMainCode;
end;
end;