Hola Valeria.
Una forma podría ser usando el evento OnChanging del TPageControl.
Código:
...
type
TForm1 = class(TForm)
private
procedure MiPageControlChanging(Sender: TObject;
var AllowChange: Boolean);
public
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
end;
var
Form1: TForm1;
MiPageControl: TPageControl;
DBGDatos,DBGDatos1: TDBGrid;
Hoja1,Hoja2: TTabSheet;
implementation
procedure TForm1.MiPageControlChanging(Sender: TObject;
var AllowChange: Boolean);
begin
case TPageControl(Sender).TabIndex of
0: DBGDatos.SetFocus;
1: DBGDatos1.SetFocus;
3: // otro TTabSheet...
4: // ...
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MiPageControl := TPageControl.Create(Self);
with MiPageControl do
begin
Parent := Self;
Align:= AlClient;
OnChanging:= MiPageControlChanging;
end;
DBGDatos:= TDBGrid.Create(self);
DBGDatos1:= TDBGrid.Create(self);
Hoja1:= TTabSheet.Create(MiPageControl);
Hoja2:= TTabSheet.Create(MiPageControl);
with Hoja1 do
begin
PageControl := MiPageControl;
DBGDatos.Parent := Hoja1;
DBGDatos.Top:= 60;
DBGDatos.Width:= 600;
DBGDatos.DataSource:= DataSource1;
ADODataSet.Active:= true;
end;
with Hoja2 do
begin
PageControl := MiPageControl;
DBGDatos1.Parent := Hoja2;
DBGDatos1.Top:= 60;
DBGDatos1.Width:= 600;
DBGDatos1.DataSource:= DataSource2;
ADODataset1.Active:= true;
end;
end;
{ FormActivate, para que aparezca con foco en DBGDatos al entrar al Form }
procedure TForm1.FormActivate(Sender: TObject);
begin
with MiPageControl do
begin
ActivePage:= Hoja1;
DBGDatos.SetFocus;
end;
end;
end.
Las variables las trabajé como globales y usé dos DataSets distintos a fin de probar el ejemplo.
Una cosa mas, el uso del parámetro self, es innecesario en este caso.
Saludos.