Fórum Como Saber o Caption de um Tlabel atraves do focus de um Tedit #27276
12/03/2010
0
Tenho um componente Tlabel que Faz a propriedade FocusControl para um edit, eu quero saber como posso Acessar a propriedade Caption do Label.
Abracos
Eduardo Richeli
Curtir tópico
+ 0Posts
12/03/2010
Thiago Santana
Gostei + 0
12/03/2010
Wilson Junior
function Ret_CaptionLabel(CompFocusControl: TWincontrol): string;
var
x: integer;
begin
Result := '';
for x := 0 to CompFocusControl.Parent.ComponentCount - 1 do
begin
if ( CompFocusControl.Parent.Components[x] is TLabel )
and ( (CompFocusControl.Parent.Components[x] as TLabel).FocusControl = CompFocusControl ) then
begin
Result := (CompFocusControl.Parent.Components[x] as TLabel).Caption;
Break;
end
;
end;
end;
Como chamar a rotina:
ShowMessage( Ret_CaptionLabel(MeuEdit) );
ShowMessage( Ret_CaptionLabel(MeuCombBox) );
ShowMessage( Ret_CaptionLabel(MeuBitbtn) );
OBS.: para funcionar esta rotina, o TLabel deve estar no mesmo componente pai que o componente passado como parâmetro (CompFocusControl).
Exemplo1: tenho um TPanel e dentro dele tenho o TLabel e o TEdit, assim funciona;
Exemplo2: tenho um TPanel e dentro dele tenho o TLabel e o TEdit esta for do TPanel, ou vice-versa, assim NÃO funciona.
Espero ter colaborado.
Gostei + 0
12/03/2010
Marcos Iwazaki
Se eu entendi bem vc tem o edit e quer acessar o label q tem o focus control p esse edit, ne?
bom se for isso...
for i:= 0 to Components.ComponentCount-1 do begin
if Components[i] is TLabel then begin
If Tlabel(Components[i]).FocusControl.Name = 'MeuEdit' then begin
// ------------ aqui vc tem o label q tem o MeuEdit como FocusControl
TLabel(Components[i]).Caption := 'Caption do MeuEdit';
end;
end;
end;
bom talvez tenha erros de sintaxe pois fiz de cabeça...
mas é algo parecido com isso.. se eu entendi o que vc queria.
Tenho um componente Tlabel que Faz a propriedade FocusControl para um edit, eu quero saber como posso Acessar a propriedade Caption do Label.
Abracos
Gostei + 0
12/03/2010
Emerson Nascimento
function TForm12.RetornaLabelFoco(Controle: TWinControl): TLabel;
var
i: integer;
begin
Result := nil;
for i := 0 to ControlCount - 1 do
if (Controls[i] is TLabel) and (TLabel(Controls[i]).FocusControl = Controle) then
begin
Result := TLabel(Controls[i]);
exit;
end;
end;
uso:
procedure TForm12.Button2Click(Sender: TObject);
var
lbl: TLabel;
begin
lbl := RetornaLabelFoco(Edit1);
if lbl <> nil then
begin
ShowMessage(lbl.Name);
lbl.Caption := 'Label Edit1';
end;
lbl := RetornaLabelFoco(Memo1);
if lbl <> nil then
begin
ShowMessage(lbl.Name);
lbl.Caption := 'Label Memo1';
end;
end;
Gostei + 0
12/03/2010
Eduardo Richeli
Gostei + 0
12/03/2010
Eduardo Richeli
Gostei + 0
14/03/2010
Emerson Nascimento
desculpe, mas não entendi o que este detalhe acrescenta....
Gostei + 0
24/03/2010
Eduardo Richeli
desculpe, mas não entendi o que este detalhe acrescenta....
acho que nestes exemplos tenho que ter acesso ao form.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)