Solved

BatchMove Copy

Posted on 1998-06-25
6
431 Views
Last Modified: 2010-04-04
I have been trying to do a Table BatchMove and have been encountering several errors.  If I leave the tables open, I receive an error that the tables are open.  If I close the tables the error complains that the process can't be performed on a closed database.  I've tried combinations closing/opening each table with no results.  How do you get this method to work?
0
Comment
Question by:blakec
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 50 total points
ID: 1355924
If you are using batCopy mode you should not set the active property of destination table to true at design time. Otherwise the IDE will reserve write rights to the table.
Somewhere in you code (before calling batchMove1.execute) set the active property of the destination table to true.

eg.
procedure TForm1.Button1Click(Sender: TObject);
begin
  table2.active:= true;
  batchMove1.execute
end;
0
 

Author Comment

by:blakec
ID: 1355925
I was attempting to use the BatchMove function, not the procedure.  Since all my tables are created and destroyed at runtime, it doesn't sound as if the IDE write is an issue.

Can I get the BatchMove function to work in Delphi 1, or do I have to create the BatchMove object?  Is there an advantage of using one over the other, other than the number of lines of code to perform the operation?

function BatchMove(ASource: TDataSet; AMode: TBatchMode): Longint;

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1355926
It seems that some other application have reserve the files. Are you running on network?

table2.batchMove( table1, batCopy) works no matter the table1/table2 is active or not. I have just tested it, it works even if table1 is opened with exclusive right. Let me know if you need my test program for batchMove. I would email it to you.

The advantage of TBatchMove is that you have more control on the batchmove operation. eg you can map the fields of source and target table if each of the two tables have different fieldnames.
(where batchmove method copy the fields data based on field number).
Just drop a tBatchMove component to the form and view the object inspector for more information.

Please post you code if you need further help.
I will only  be back on June 28.





0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:blakec
ID: 1355927
The tables used in this program are used only by this program for single instance runs.  There will probably never be a sharing violation because the program is designed to run on non-networked laptops.

In this instance, the tables need to be a carbon copy of each other because they may need to be used interchangably.  Following is the source code causing the problem.  The program GPF's on the BatchMove call and the error varies depending on whether the source/destination tables are open or closed.

function LoadArchiveTbl: bool;
begin
     LoadArchiveTbl := True;

     with PadMod1, FileLstTbl do
     begin

          Active := True;
          RestoreTbl.Active := True;

          try
          if BatchMove(RestoreTbl, batCopy) <> RecordCount then
          begin
               LoadArchiveTbl := False;
               FailMsg(BAT_COPY_ERR);
          end;
          except on E: exception do
             begin
                  MsgOk2(E.Message);
                  LoadArchiveTbl := False;
             end;
          end;
          {RestoreTbl.Active := True;}
     end;
end;

P.S.  I didn't realize I had a BatchMove component.  This is such a cool programming tool. :) Wish I could convince my Microsoft Office.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1355928
As the code you post is not complete I have made some assumptions to test it:

1. Assume padMod1, FailMsg, MsgOk2 is irrelevant to the subject.
2. since LoadArchiveTbl is not prefixed with form name, I presume fileLstTbl1 is declared as a global variable. Consequently I have to declare FileLstTbl and restoreTbl as a global variable (type ttable) and created them at runtime.
3. I also write an onclick event to call LoadArchiveTbl

Test result: Everything is working fine.

My second test is the more conventional method: create the tow tables at designtime. have I also modified the LoadArchiveTbl function as follows:

function TForm1.LoadArchiveTbl: bool;
begin
  LoadArchiveTbl := True;
  with {PadMod1,} FileLstTbl do
  begin
    Active := True;
    RestoreTbl.Active := True;
    try
     if BatchMove(RestoreTbl, batCopy) <> RecordCount then begin
       LoadArchiveTbl := False;
      { FailMsg(BAT_COPY_ERR);}
     end;
       except on E: exception do
          begin
{               MsgOk2(E.Message);}
               LoadArchiveTbl := False;
          end;
       end;
       {RestoreTbl.Active := True;}
  end;
end;

This test works fine too.

Please check what I assume above is the same as what you did in your program. If you still cannot get it work, try to create a new test program to see whether the batchMove function works. If the same error still come out on you test program (which is very unlikely), I would advise you to reinstall you delphi.

goodluck
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1355929
I would assume that one of our 2 tables are corrupt...try your test on new tables...I would pick one of the tables from Delphi\Demos\Data

Also make sure that you have enough disk space for the operation.

How large are your tables???

What kinda of tables are we using???


Rick
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question