RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TSQLTable.Active Property

Specifies whether or not a dataset is open.

Pascal
property Active: Boolean;
C++
__property Boolean Active;

Use Active to determine or set whether a dataset is populated with data. When Active is false, the dataset is closed; the dataset cannot read or write data and data-aware controls can not use it to fetch data or post edits. When Active is true, the dataset can be populated with data. It can read data from a database or other source (such as a provider). Depending on the CanModify property, active datasets can post changes. 

Setting Active to true:

  1. Generates a BeforeOpen event.
  2. Sets the dataset state to dsBrowse.
  3. Establishes a way to fetch data (typically by opening a cursor).
  4. Generates an AfterOpen event.

If an error occurs while opening the dataset, dataset state is set to dsInactive, and any cursor is closed. 

Setting Active to false:

  1. Triggers a BeforeClose event.
  2. Sets the State property to dsInactive.
  3. Closes the cursor.
  4. Triggers an AfterClose event.

An application must set Active to false before changing other properties that affect the status of a database or the controls that display data in an application.

Note: Calling the Open method sets Active to true; calling the Close method sets Active to false.
 

Delphi Examples: 

 

{
This example requires a database with the following name or
in the form of a *.DB file in the following path.  The table
should be closed when changing the database.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Customers.Active := False;
  try
  { First try to use an alias }
    Customers.DatabaseName := 'DBDEMOS';
    Customers.Active := True;
  except
    on EDatabaseError do
    begin
      { If that fails, try to use the drive and directory }
      Customers.TableName := 'Flights';
      Customers.DatabaseName :=
        'c:\Documents and Settings\All Users\Documents\RAD Studio\5.0\Demos\IntraWeb\Win32\FlightInformation\Data';
      Customers.Active := True;
    end;
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!