unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OnActivate, DB, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls;

type
  TForm2 = class(TForm)
    DBGrid2: TDBGrid;
    DBNavigator2: TDBNavigator;
    Button1: TButton;
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

// BeginExample: OnActivate2
// Event: Forms.TCustomForm.OnActivate
// Property: Classes.TComponent.ComponentCount
// Property: Classes.TComponent.Components

// BeginCode
{
The following code sets the DataSource for a DBGrid
component in Form2 to the currently selected data source in
a list provided in Form1. This allows users to specify the
desired information in Form1, and then move to Form2 to view
the information. Select an item in the listbox and then
activate Form2 by clicking in it. Also, set the visible property
of Form2 to true.
}
procedure TForm2.FormActivate(Sender: TObject);
begin
  if (Form1Done) then
  begin
    DBGrid2.DataSource :=
      Form1.ListBox1.Items.Objects[Form1.ListBox1.ItemIndex] as TDataSource;
    DBNavigator2.DataSource :=
      Form1.ListBox1.Items.Objects[Form1.ListBox1.ItemIndex] as TDataSource;
  end;
end;
// EndCode
// EndExample: OnActivate2
end.
