Dúvidas com o FindComponent...

Delphi

10/12/2003

Preciso alimentar os TEdit do meu formulario com os dados de uma query.
Criei esta rotina, mas não está dando certo.
Se alguem poder me ajudar!!!

procedure TForm_Master.Find_Funcionario(FUN_CODIGO: Integer);
var
i : Integer;
Controle : String;
begin
vFUN_CODIGO := FUN_CODIGO;
with DMDados, FIND_QUERY do
begin
Close;
SQL.Clear;
SQL.Add(´SELECT * FROM FUNCIONARIOS ´+
´WHERE FUN_CODIGO =:FUN_CODIGO´);
ParamByName(´FUN_CODIGO´).AsInteger := vFUN_CODIGO;
Open;
// Preenche os Campos
for i := 0 to FIND_QUERY.FieldCount - 1 do
begin
Controle := ´EDT_´+FIND_QUERY.Fields[i].FieldName;
TabFuncionarios.FindComponent(Controle);
if TabFuncionarios.Controls[i] is TEdit then
(TabFuncionarios.Controls[i] as TCustomEdit).Text := FIND_QUERY.Fields[i].AsString;
end;
end;
end;

No meu sistema os TEdit tem o mesmo nome do TField antecedido de ´EDT_´.


Sanwilly

Sanwilly

Curtidas 0

Respostas

Deus

Deus

10/12/2003

Hmmm... veja se funciona trocar a variável [i:bbbe6c20a6]controle[/i:bbbe6c20a6] de [b:bbbe6c20a6]String[/b:bbbe6c20a6] para [b:bbbe6c20a6]TEdit[/b:bbbe6c20a6] e trocar a parte

// Preenche os Campos 
for i := 0 to FIND_QUERY.FieldCount - 1 do 
begin 
  Controle := ´EDT_´+FIND_QUERY.Fields[i].FieldName; 
  TabFuncionarios.FindComponent(Controle); 
  if TabFuncionarios.Controls[i] is TEdit then 
    (TabFuncionarios.Controls[i] as TCustomEdit).Text := FIND_QUERY.Fields[i].AsString; 
end; 


por

// Preenche os Campos 
for i := 0 to FIND_QUERY.FieldCount - 1 do 
begin
  try 
    Controle := TEdit(TabFuncionarios.FindComponent(´EDT_´+FIND_QUERY.Fields[i].FieldName)); 
    Controle.Text := FIND_QUERY.Fields[i].AsString; 
  except
  end;
end;



GOSTEI 0
POSTAR