Solved

Packing Paradox TTables in D3 Standard

Posted on 1998-09-06
6
305 Views
Last Modified: 2010-04-06
How do I pack and regenerate indexes on Paradox tables using Delphi 3 Standard edition. I know it can be done in Database Desktop but how do I achieve it at runtime.
I can't find any reference to it in the help files.

I'm probably missing something really simple but I'm tearing my hair out here.

Please help me people !!
0
Comment
Question by:elkiors
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 100 total points
ID: 1338775
From Borland Documenatation:
http://www.inprise.com/devsupport/bde/bdeapiex/dbidorestructure.html

Example 2: Pack a Paradox or dBASE table.

           This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
           This function will also regenerate all out-of-date indexes (maintained indexes).
           This example uses the following input:
           PackTable(Table1)
           The function is defined as follows:

           // Pack a Paradox or dBASE table
           // The table must be opened execlusively before calling this function...
           procedure PackTable(Table: TTable);
           var
             Props: CURProps;
             hDb: hDBIDb;
             TableDesc: CRTblDesc;

           begin
             // Make sure the table is open exclusively so we can get the db handle...
             if Table.Active = False then
               raise EDatabaseError.Create('Table must be opened to pack');
             if Table.Exclusive = False then
               raise EDatabaseError.Create('Table must be opened exclusively to pack');

             // Get the table properties to determine table type...
             Check(DbiGetCursorProps(Table.Handle, Props));

             // If the table is a Paradox table, you must call DbiDoRestructure...
             if Props.szTableType = szPARADOX then
             begin
               // Blank out the structure...
               FillChar(TableDesc, sizeof(TableDesc), 0);
               //  Get the database handle from the table's cursor handle...
               Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
               // Put the table name in the table descriptor...
               StrPCopy(TableDesc.szTblName, Table.TableName);
               // Put the table type in the table descriptor...
               StrPCopy(TableDesc.szTblType, Props.szTableType);
               // Set the Pack option in the table descriptor to TRUE...
               TableDesc.bPack := True;
               // Close the table so the restructure can complete...
               Table.Close;
               // Call DbiDoRestructure...
               Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
             end
             else
               // If the table is a dBASE table, simply call DbiPackTable...
               if Props.szTableType = szDBASE then
                 Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
               else
                 // Pack only works on PAradox or dBASE; nothing else...
                 raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +
                          'type to pack');

             Table.Open;
           end;
0
 

Author Comment

by:elkiors
ID: 1338776
Please bear with me while I check out your answer, I'm a little pushed for time for checking it out. Give me a couple of days and I'll Accept or Reject.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338777
OK, if you have problems then before the first Check(...
write:                                Check(dbiInit(Nil)); //initializing the BDE
and on the end write:       DbiExit;               //freening resources
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:elkiors
ID: 1338778
Ronit:

I'm sorry but I can't get this to compile, if you could make this a stand alone unit that I can just add to my projects it would be great.

At the moment it seems to be stopping on var types declared at the front of the PackTable procedure, I've tried to do a search for them in the help files so that I can trace the standard units requirements but no luck so far. Unfortunately, I'm still a novice, so the really low-level stuff like this is a bit beyond me.

I've upped the points as much as I can to help you consider the extra bit of effort needed on your part

thanx in advance for all your help

regards

elkiors



unit dbPack;

interface

procedure PackTable(Table: TTable);

implementation

// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:

// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;

begin
  // Make sure the table is open exclusively so we can get the db handle...
  if Table.Active = False then raise EDatabaseError.Create('Table must be opened to pack');
  if Table.Exclusive = False then raise EDatabaseError.Create('Table must be opened exclusively to pack');

  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));

  // If the table is a Paradox table, you must call DbiDoRestructure...
  if Props.szTableType = szPARADOX then
  begin
    // Blank out the structure...
    FillChar(TableDesc, sizeof(TableDesc), 0);
    //  Get the database handle from the table's cursor handle...
    Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
    // Put the table name in the table descriptor...
    StrPCopy(TableDesc.szTblName, Table.TableName);
    // Put the table type in the table descriptor...
    StrPCopy(TableDesc.szTblType, Props.szTableType);
    // Set the Pack option in the table descriptor to TRUE...
    TableDesc.bPack := True;
    // Close the table so the restructure can complete...
    Table.Close;
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
  end
  else
    // If the table is a dBASE table, simply call DbiPackTable...
    if Props.szTableType = szDBASE then
      Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
    else
      // Pack only works on PAradox or dBASE; nothing else...
      raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' + 'type to pack');
        Table.Open;
end;

end.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338779
Did you add to the uses --->BDE, DBTables,DB?
0
 

Author Comment

by:elkiors
ID: 1338780
thanx ronit, just what i need
the final compilable unit is listed below so anyone else can use it without any need to modify it further.


---------------------------------
unit dbPack;

interface

uses BDE, DBTables, DB, sysutils;

procedure PackTable(Table: TTable);

implementation

// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:

// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;

begin
  // Make sure the table is open exclusively so we can get the db handle...
  if Table.Active = False then raise EDatabaseError.Create('Table must be opened to pack');
  if Table.Exclusive = False then raise EDatabaseError.Create('Table must be opened exclusively to pack');

  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));

  // If the table is a Paradox table, you must call DbiDoRestructure...
  if Props.szTableType = szPARADOX then
  begin
    // Blank out the structure...
    FillChar(TableDesc, sizeof(TableDesc), 0);
    //  Get the database handle from the table's cursor handle...
    Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
    // Put the table name in the table descriptor...
    StrPCopy(TableDesc.szTblName, Table.TableName);
    // Put the table type in the table descriptor...
    StrPCopy(TableDesc.szTblType, Props.szTableType);
    // Set the Pack option in the table descriptor to TRUE...
    TableDesc.bPack := True;
    // Close the table so the restructure can complete...
    Table.Close;
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
  end
  else
    // If the table is a dBASE table, simply call DbiPackTable...
    if Props.szTableType = szDBASE then
      Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
    else
      // Pack only works on PAradox or dBASE; nothing else...
      raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' + 'type to pack');
        Table.Open;
end;

end.
----------------------------------------------------

thanks once again,

enjoy the points,

c u on another thread.

elkiors (Darren)

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now