Re: [delphi-br] Re: [lista-delphi ] Como saber se a Classe está ou nã o registrada? - RESOLVIDO + CONTRIBUICAO
Valeu João Funcionou direitinho!!! pessoal segue o código que estou utilizando para chamar forms, sem declarar sua unit na uses do meu form principal. function AbreForm(AForm: String; ADono: TComponent; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; i: Integer; begin Pc := GetClass('t' + AForm); if (Pc nil) then begin nome := nil; i := 0; while I Screen.FormCount do begin if Screen.Forms[I] is Pc then Nome := Screen.Forms[I]; Inc(I); end; if nome = nil then TFormClass(Pc).Create(ADono).Show else nome.Show; end; end; antes do end. da unit do form a ser chamar deve conter as seguintes linhas: initialization RegisterClass(TMeuForm) finalization UnRegisterClass(TMeuForm) end. Abraços! Thiago Filiano 11-8288-4402 msn: [EMAIL PROTECTED] Joao Morais escreveu: Adriano Santos wrote: Ai galera, o Thiago trabalha comigo aqui. O que precisamos é o seguinte: Nesta função abaixo nós criamos o form passando para a função o nome dele, porém precisamos saber se o mesmo já foi criado e então apenas dar um Show no mesmo. Não estamos conseguindo montar corretamente a função. Teria que ser mais ou menos isso: function AbreForm(AForm: String; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; begin Pc := GetClass('t' + AForm); if (Pc nil) then {aqui teria que ter uma verificação} if not Form_Já_Criado_E_Registrado then Nome := nil; I := 0 while I Screen.FormCount do begin if Screen.Forms[I] is Pc then Nome := Screen.Forms[I]; Inc(I); end; begin with TFormClass(Pc).Create(frmPrincipal) do try Show; finally Free; end; Show seguido de Free irá destruir o form logo depois de apresentá-lo. Use ShowModal ou destrua o form só quando ele for fechado (Action := caFree). end else Show; end; -- João Morais Mensagem original De: Thiago Filiano (America Soft) [EMAIL PROTECTED] mailto:thiago%40americasoft.com.br Para: delphi-br@yahoogrupos.com.br mailto:delphi-br%40yahoogrupos.com.br Assunto: [lista-delphi] Como saber se a Classe está ou não registrada? Data: 14-02-2007 13:44 Pessoal, Bom dia!! Tenho a seguinte função para chamar os forms: function AbreForm(AForm: String; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; begin Pc := GetClass('t' + AForm); if (Pc nil) then with TFormClass(Pc) .Create(frmPrincipal) do try Show; Update; finally Free; end; end;
Re: [delphi-br] Re: [lista-delphi ] Como saber se a Classe está ou nã o registrada? - RESOLVIDO + CONTRIBUICAO
Thiago Filiano (America Soft) wrote: Valeu João Funcionou direitinho!!! pessoal segue o código que estou utilizando para chamar forms, sem declarar sua unit na uses do meu form principal. function AbreForm(AForm: String; ADono: TComponent; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; i: Integer; begin Pc := GetClass('t' + AForm); if (Pc nil) then begin nome := nil; i := 0; while I Screen.FormCount do Altere seu while para este aqui: while not Assigned(Nome) and (I Screen.FormCount) do -- João Morais begin if Screen.Forms[I] is Pc then Nome := Screen.Forms[I]; Inc(I); end; if nome = nil then TFormClass(Pc).Create(ADono).Show else nome.Show; end; end; antes do end. da unit do form a ser chamar deve conter as seguintes linhas: initialization RegisterClass(TMeuForm) finalization UnRegisterClass(TMeuForm) end. Abraços! Thiago Filiano 11-8288-4402 msn: [EMAIL PROTECTED] Joao Morais escreveu: Adriano Santos wrote: Ai galera, o Thiago trabalha comigo aqui. O que precisamos é o seguinte: Nesta função abaixo nós criamos o form passando para a função o nome dele, porém precisamos saber se o mesmo já foi criado e então apenas dar um Show no mesmo. Não estamos conseguindo montar corretamente a função. Teria que ser mais ou menos isso: function AbreForm(AForm: String; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; begin Pc := GetClass('t' + AForm); if (Pc nil) then {aqui teria que ter uma verificação} if not Form_Já_Criado_E_Registrado then Nome := nil; I := 0 while I Screen.FormCount do begin if Screen.Forms[I] is Pc then Nome := Screen.Forms[I]; Inc(I); end; begin with TFormClass(Pc).Create(frmPrincipal) do try Show; finally Free; end; Show seguido de Free irá destruir o form logo depois de apresentá-lo. Use ShowModal ou destrua o form só quando ele for fechado (Action := caFree). end else Show; end; -- João Morais Mensagem original De: Thiago Filiano (America Soft) [EMAIL PROTECTED] mailto:thiago%40americasoft.com.br Para: delphi-br@yahoogrupos.com.br mailto:delphi-br%40yahoogrupos.com.br Assunto: [lista-delphi] Como saber se a Classe está ou não registrada? Data: 14-02-2007 13:44 Pessoal, Bom dia!! Tenho a seguinte função para chamar os forms: function AbreForm(AForm: String; AEstilo: TBorderStyle = bsSingle; AShow: Boolean = True): Boolean; var Pc: TPersistentClass; nome: TForm; begin Pc := GetClass('t' + AForm); if (Pc nil) then with TFormClass(Pc) .Create(frmPrincipal) do try Show; Update; finally Free; end; end;