Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does one Empty a TTable 2

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA

I have tried the following

procedure ButtonClick(Sender: TObject);
begin
with tblMine do
begin
tblMine.EmptyTable;
end;
end;

...which gives me exception

'Table cannot be opened for exclusive use.'

Can anyone please tell me how to overcome this?

I have also tried

with tblMine do
begin
try
tblMine.DisableControls;
tblMine.First;
while not tblMine.EOF do
begin
tblMine.Delete;
tblMine.Next;
end;
finally
tblMine.EnableControls;
end;
end;

Which only clears 5 out of 10 then 3 out of 5
then 1 out of 2 then the last one.

Why does this routine do this?

Anyone?
 
hi,

the first one, to use the function emptytable you have you close the table and disconneted it from the tTable component you use. It works the same as deletefile. You cann't do that if you have the file opened and connected to the application.


the second one donn't use the line tblMine.next. If you delete a record the next will be automatically performed.
if you use .next you will skipp one record.

Steph [Bigglasses]
 

>to use the function emptytable you have you close the >table and disconneted it from the tTable component you use.

Many thanks for that! :)

Buy how about some code for this strugler .. please?
:) :)

procedure ButtonClick(Sender: TObject);
begin
with tblMine do
begin

?????????

end;
end;
 
hi,

your code is allright for emptying the table.

to disconnect:

tblMine.Active := False;
tblMine.Exclusive := True ; // very importanted
tblMine.emptyTable;
tblMine.Active := True;

Steph [Bigglasses]
 
Thanks Steph!

Case closed.

However it should be mentioned that this routine produces a Table busy exception if I run it during Design Time. It only works (perfectly) for me if I leave Delphi altogether and run the .exe file.
 
If you are testing the program under the IDE and you have the Active property of the TTable set to true then the IDE has the table open. In this case your application cannot get exclusive control of the TTable.

The solution is to set Active to false in the IDE and explicitly open the TTable in your application.

Andrew

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top