TTable.EmptyTable (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to empty a TTable using the Table.EmptyTable method.

Place a TTable component on the form and, from the Object Inspector, set the DatabaseName property to "DBDEMOS" and the TableName to one of the table names (for example, "biolife.db").

To be able to see the table, place a TBGrid component and a TDataSource component on the form.

To do the example, you also need to add a TTable on the form and set its name to "EmptyTable".

Code

procedure TForm1.FormCreate(Sender: TObject);
begin
//link the DBGrid to the Table to see the data from the table in DBGrid
DataSource1.DataSet:=Table1;
DBGrid1.DataSource:=DataSource1;
Table1.Open;
end;
procedure TForm1.EmptyTableClick(Sender: TObject);
begin
  try
    Table1.Close; 
    Table1.Exclusive := true; 
    Table1.EmptyTable;
    Table1.Exclusive := False; 
    Table1.Open;
  except
    on E : Exception do   ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
  end;

end;

Uses