Recent

Author Topic: (Solved)DBF Packtable  (Read 3821 times)

MVD

  • New Member
  • *
  • Posts: 23
(Solved)DBF Packtable
« on: September 21, 2017, 12:07:47 pm »
Hi,
I have a program that is working very well, I have only one problem.
I am working with DBASE VII tables ( I know, is old  and there are more modern databases but I am confortable with it because I was programming in Delphi6 long time ago) and the table is open Shared.(So we can use the program with 2 or more users). I have a menu item to clean up the database. Regenerating indexes is no problem but when I try to pack the table with ".packtable" I have a problem. To pack the table I have to set the exclusive propertie, If a set:
Code: Pascal  [Select][+][-]
  1. [color=red]  hoofdvenster.Dbf1.Exclusive:=true;
  2.    hoofdvenster.Dbf1.PackTable; [/color]
I got the message : "Exclusive access is required for this operation"
If I set:
   
Code: Pascal  [Select][+][-]
  1. [color=red]hoofdvenster.Dbf1.close;
  2.    hoofdvenster.Dbf1.Exclusive:=true;
  3.    hoofdvenster.Dbf1.open:=true  ;
  4.    hoofdvenster.Dbf1.PackTable; [/color]
I got the message : "unable to open file "C:\x.dbf"
??????
« Last Edit: September 22, 2017, 08:21:05 pm by MVD »

fred

  • Full Member
  • ***
  • Posts: 201
Re: DBF Packtable
« Reply #1 on: September 21, 2017, 01:35:06 pm »
Perhaps the other has the database open so it can't be opened in Exclusive mode?

MVD

  • New Member
  • *
  • Posts: 23
Re: DBF Packtable
« Reply #2 on: September 21, 2017, 02:58:23 pm »
I am sure that de DBF is not used, so normal "exclusive" must be OK.
It is like I can not override the options I see in the object inspector.
To work I have to set the database propertie active to false and the exclusive propertie to true ( if I let the active propertie to
true I get the compiler error "unable to open file "x.dbf").
The program will work in exclusive mode but setting exclusive to "false" will not change this.
procedure THoofdvenster.MenuItem3Click(Sender: TObject);
begin
   hoofdvenster.Dbf1.Active:=true  ;
   hoofdvenster.Dbf1.PackTable;
   hoofdvenster.Dbf1.Exclusive:=false;
   hoofdvenster.Dbf1.RegenerateIndexes;
   form_lijsten.Dbf2.RegenerateIndexes;
end;
In the program i can not override the exlusive option  from the object inspector.         

fred

  • Full Member
  • ***
  • Posts: 201
Re: DBF Packtable
« Reply #3 on: September 21, 2017, 03:47:25 pm »
You can only change Exclusive when the database is closed/active = false

From the TDbf.pdf file:

Quote
7.12 Exclusive
property Exclusive: Boolean read FExclusive write FExclusive default false;
Use Exclusive to prevent other applications from accessing a table while it is open in this
application. Before opening the table, set Exclusive to true. A table must be closed before
changing the Exclusive property.
When Exclusive is true, then when the application successfully opens the table, no other
application can access it. If the table for which the application has requested exclusive access
is already in use by another application, an exception is thrown. To handle such exceptions,
wrap the code that opens the table in a try..catch block. See also TryExclusive.

Do not set Exclusive to true at design time if you also set the Active property to true at
design time. In this case an exception is thrown because the table is already in use by the
IDE.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: DBF Packtable
« Reply #4 on: September 21, 2017, 05:51:07 pm »
I am sure that de DBF is not used, so normal "exclusive" must be OK.
If you forgot to uncheck TDBF's Active property in design mode, then in runtime you have 2 active users on the same DBF.  ::)
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MVD

  • New Member
  • *
  • Posts: 23
Re: DBF Packtable
« Reply #5 on: September 21, 2017, 09:50:39 pm »
I am sure that de DBF is not used, so normal "exclusive" must be OK.
If you forgot to uncheck TDBF's Active property in design mode, then in runtime you have 2 active users on the same DBF.  ::)
T :Dhanks, this is the solution, it seems as simple as one thinks about it.

Fred, where did you find the TDbf.pdf file?

fred

  • Full Member
  • ***
  • Posts: 201
Re: DBF Packtable
« Reply #6 on: September 22, 2017, 08:58:19 am »

 

TinyPortal © 2005-2018