Solved

BatchMove Copy

Posted on 1998-06-25
6
428 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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