Hola,
tienes un error de concepto. Si le estas pasando el objeto que quieres darle el foco, ¿para que lo vuelves a buscar con findcomponent?
Código Delphi
[-]
procedure EstablecerFoco(Formulario : TForm; Control : TWinControl);
begin
Try
Formulario.FindComponent('Control') as TWinControl;
Formulario.Control.SetFocus;
Except
MessageDlg('No se lozalizo el control ' + Control.Name, mtInformation,[mbOk], 0);
End;
end;
aparte que tendrias que usar el control.Name. Ten en cuenta que una cosa es el nombre del objeto, y otra el de la variable con el que tu estas trabajando:
Código Delphi
[-]
var
o1 : TControl;
o2 : TControl;
r : TControl;
edit1 : TEdit;
begin
o1 := TControl.Create(self);
o2 := TControl.Create(self);
...
o1.Name := 'control';
o2.Name := 'o1';
r := FindComponent(o2.Name) as Tcontrol; r := FindComponent(o1.Name) as Tcontrol; r := FindComponent('o1') as Tcontrol r := FindComponent('control') as TControl end;
para lo que quieres hacer, con la funcion que tienes, tansolo debes hacer
Código Delphi
[-]
procedure EstablecerFoco(Control : TWinControl);
begin
if assigned(Control) then Control.SetFocus;
end;
y si quieres encontrar algun objeto por su nombre entonces
Código Delphi
[-]
procedure EstablecerFoco(Formulario : TForm; s : string);
begin
try
(Formulario.FindComponent(s) as TWinControl).SetFocus;
except
...
end;
end;
espero se te haya aclarado algo mas. Un saludo.