DisableControls (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

Usually DisableControls is called within the context of a try...finally block that re-enables the controls even if an exception occurs. For example:

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Clear;
  ListBox1.Items[0]:= 'Destination Airports:';
  with Flights do
  begin
    DisableControls;
    try
      First;
      i:= 1;
      ListBox1.Items[0]:= 'Destination Airports:';
      while not Eof do
      begin
        ListBox1.Items[i]:= Fields[2].Value;;
        i:= i + 1;
        Next;
      end;
    finally
      EnableControls;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Flights:= TTable.Create(Form1);
  with Flights do
  begin
    TableName := 'Flights';
    // This path depends on the Demos directory of your RAD Studio installation.
    DatabaseName :=
      'c:\Documents and Settings\All Users\Documents\RAD Studio\6.0\Demos\IntraWeb\Win32\FlightInformation\Data';

  end;
  DS2.DataSet:= Flights;
  DBGrid2.DataSource.DataSet:= Flights;
  Flights.Active:= True;
end;

Uses

Personal tools
Assistance