Treeview Delphi with BD link

Asked

Viewed 82 times

1

I have created a Treeview with the data that is in a table in the BD, and has a field that contains the name in the form.
How To Give One ShowModal at the event OnClick of Treeview taking the name of the form that is in the table field?

Follows the code:

procedure CriaFormpeloNome(const FrmNome : string);
var
  FrmClass : TFormClass;
  Frm : TForm;
begin

  try
    FrmClass := TFormClass(FindClass(FrmNome));
    Frm      := FrmClass.Create(application);
  except
    //não achou a classe
    showmessage('Não achou a classe');
  end;
end;


procedure TFormFrontend.TreeView2DblClick(Sender: TObject);
var
Form2 : string;
begin
zmenu.SQL.Clear;
zmenu.SQL.Add('Select * from tab_menu');
zmenu.SQL.Add('WHERE id =:id');
zmenu.Params.ParamByName('id').value:= TreeView2.Selected.AbsoluteIndex;
zmenu.Open;
Form2:= zmenuarquivo.AsString;
Form2 := concat('T',Form2);
CriaFormpeloNome(Form2);
end;
  • 1

    Include your code, it’s easier for someone to help you ;)

1 answer

0

The only thing I see missing in your code is that to use Findclass you need to call Registerclass first. I would say you have to initially call Registerclass for all classes of Forms you want to open and then the code you have works.

This little example works:

procedure CriaFormpeloNome(const FrmNome : string);
var
   FrmClass : TFormClass;
   Frm : TForm;
begin
   try
      FrmClass := TFormClass(FindClass(FrmNome));
      Frm      := FrmClass.Create(application);
      if Frm<>nil then
        frm.ShowModal;
   except
     //não achou a classe
     showmessage('Nao Achou a classe');
   end;
end;

procedure TForm5.BitBtn1Click(Sender: TObject);
begin
  RegisterClass(TForm5);
  CriaFormpeloNome('TForm5');
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.