2009/2/4 contato.pcsolution <contato.pcsolut...@yahoo.com.br>:
> procedure CreateFormFromName(const FormName : string);
> var
> fc : TFormClass;
> f : TForm;
> begin
> fc := TFormClass(FindClass(FormName));
> f := fc.Create(Application);
> f.Show;
> end;

Essa rotina tá perigosa. Arruma pra algo mais ou menos assim:

function CreateFormFromName(const FormName : string): Boolean;
var
  fc : TClass;
  f : TForm;
begin
  fc := FindClass(FormName);
  Result := Assigned(fc) and fc.InheritsFrom(TForm);
  if Result then
    fc.Create(Application).Show;
end;

Se retornar False, o form não foi encontrado.


> PARTE QUE ACONTECE O ERRO..
>
> procedure TMainForm.Button1Click(Sender: TObject);
> begin
> FirstForm.Label1.Caption := 'Testando';
> end;

Adapte a rotina acima com os truques desse artigo:

http://blog.joaomorais.com.br/2008/08/31/dica-gerenciamento-form.html

Joao Morais

Responder a