Identity, filters, MasterDetail and CachedUpdates, Please Help me

hi. every body.
i have a question????
i have a similar problem, i'm using TTables y master detail. if my Master
Table is filtered, when i post, the master/detail lost, please could anybody
help me??.

My code is:

procedure TMasterDataModule.tblMasterTableBeforePost(
  DataSet: TDataSet);
var
   vQuery : TQuery;
begin
   gInserting := (tblMovimientoBanco.State = dsInsert);

  datMain.Database.StartTransaction;

  tblDetailTable.DisableControls;
end;

procedure TMasterDataModule.tblMasterTableAfterPost(
  DataSet: TDataSet);
begin

  if gInserting then
  begin
    gId := GetIdentity( datPrincipal.Contab);  // Function (SELECT
@@Identity) = SQL SERVER

    if tblDetailTable.UpdatesPending  then
      tblDetailTable.UpdateRecordTypes := [rtInserted, rtModified];

    tblDetailTable.First;
    while not (tblDetailTable.Eof) do
    begin
      tblDetailTable.Edit;
      tblDetailTableId.AsInteger := gId;
      tblDetailTable.Post;
    end;
    tblDetailTable.UpdateRecordTypes := [rtInserted, rtModified,
rtUnmodified, rtDeleted];
    tblDetailTable.ApplyUpdates ;
    datMain.Database.Commit;
end;

Im using SQL Server 7, DELPHI 4. and Nt 4.00

Thanks a lot.