Icon Frequently Asked Questions

I need to provide the equivalent functionality that is provided in the TBatchMove component provided with the BDE, can I do this with DBISAM ?

Yes, just use the following code to provide TBatchMove type of functionality in DBISAM.

TDBISAMBatchMoveType = (bmtAppend,bmtAppendUpdate,bmtCopy,
                        bmtDelete,bmtUpdate);

procedure BatchMove(SourceTable, DestTable: TDBISAMTable;
                    MoveType: TDBISAMBatchMoveType);
var
   I: Integer;
   RecordWasFound: Boolean;
begin
   SourceTable.DisableControls;
   DestTable.DisableControls;
   try
      with SourceTable do
         begin
         Open;
         FieldDefs.Update;
         IndexDefs.Update;
         end;
      with DestTable do
         begin
         if (not Exists) or (MoveType=bmtCopy) then
            begin
            Close;
            FieldDefs.Assign(SourceTable.FieldDefs);
            IndexDefs.Assign(SourceTable.IndexDefs);
            CreateTable(SourceTable.LocaleID,
                        SourceTable.UserMajorVersion,
                        SourceTable.UserMinorVersion,
                        SourceTable.Encrypted,
                        SourceTable.Password,
                        SourceTable.Description,
                        SourceTable.IndexPageSize,
                        SourceTable.BlobBlockSize,
                        SourceTable.LastAutoIncValue);
            end;
         Open;
         IndexName:='';
         end;
      DestTable.LockTable;
      try
         with SourceTable do
            begin
            IndexName:='';
            First;
            end;
         while not SourceTable.EOF do
            begin
            RecordWasFound:=False;
            if (MoveType in [bmtAppend,bmtAppendUpdate,
                             bmtUpdate,bmtDelete]) then
               begin
               DestTable.SetKey;
               for I:=0 to DestTable.IndexFieldCount-1 do
                  begin
                  DestTable.IndexFields[I].Assign(
                    SourceTable.FieldByName(
                      DestTable.IndexFields[I].FieldName));
                  end;
               RecordWasFound:=DestTable.GotoKey;
               end;
            if RecordWasFound then
               begin
               if (MoveType in [bmtAppendUpdate,
                                bmtUpdate]) then
                  begin
                  DestTable.Edit;
                  for I:=0 to SourceTable.FieldCount-1 do
                     DestTable.FieldByName(
                       SourceTable.Fields[I].FieldName).
                         Assign(SourceTable.Fields[I]);
                  DestTable.Post;
                  end
               else if (MoveType=bmtDelete) then
                  DestTable.Delete;
               end
            else
               begin
               if (MoveType in [bmtAppend,bmtAppendUpdate,
                                bmtCopy]) then
                  begin
                  DestTable.Insert;
                  for I:=0 to SourceTable.FieldCount-1 do
                     DestTable.FieldByName(
                       SourceTable.Fields[I].FieldName).
                         Assign(SourceTable.Fields[I]);
                  DestTable.Post;
                  end;
               end;
            SourceTable.Next;
            end;
      finally
         DestTable.UnlockTable;
      end;
   finally
      SourceTable.EnableControls;
      DestTable.EnableControls;
   end;
end;

You can find the equivalent C++Builder files here:

C++Builder TBatchMove Code
Image