cd.rafael,
Cita:
Empezado por cd.rafael
He revisado muchos temas respecto al manejo de forms dentro de una dll y hasta ahora no he podido resolver mi problema, que a continuación expongo: Tengo un ejecutable normal el cual invoca a una dll que a su vez lanza una form. Si dicha form la muestro con "ShowModal" todo funciona bien, pero si la dejo solo como "Show", el ejecutable deja de responder.
|
Revisa este código:
Código Delphi
[-]
Library DLLForm;
uses
SysUtils,
Forms,
UnitFrmDLL in 'UnitFrmDLL.pas' ;
{$R *.res}
procedure ShowForm; StdCall;
var
f : TFrmDLL;
begin
f := TFrmDLL.Create(Application);
f.Show;
end;
exports
ShowForm;
begin
end.
El código anterior declara una DLL
(DLLForm) que
Exporta el Procedure ShowForm el cual muestra un formulario con el método Show declarado en la unidad
UnitFrmDLL.pas
Revisa el código de la Unidad
UnitFrmDLL del DLL anterior.
Código Delphi
[-]
unit UnitFrmDLL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFrmDLL = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
public
end;
function mSum(x1, x2 : Double) : Double;
function mSub(x1, x2 : Double) : Double;
function mMul(x1, x2 : Double) : Double;
function mDiv(x1, x2 : Double) : Double;
implementation
{$R *.dfm}
function mSum(x1, x2 : Double) : Double;
begin
Result := x1 + x2;
end;
function mSub(x1, x2 : Double) : Double;
begin
Result := x1 - x2;
end;
function mMul(x1, x2 : Double) : Double;
begin
Result := x1 * x2;
end;
function mDiv(x1, x2 : Double) : Double;
begin
Result := x1 / x2;
end;
procedure TFrmDLL.Button1Click(Sender: TObject);
var
x1, x2 : Double;
begin
x1 := StrToFloat(Edit1.Text);
x2 := StrToFloat(Edit2.Text);
ShowMessage(FloatToStr(mSum(x1,x2)));
end;
procedure TFrmDLL.Button2Click(Sender: TObject);
var
x1, x2 : Double;
begin
x1 := StrToFloat(Edit1.Text);
x2 := StrToFloat(Edit2.Text);
ShowMessage(FloatToStr(mSub(x1,x2)));
end;
procedure TFrmDLL.Button3Click(Sender: TObject);
var
x1, x2 : Double;
begin
x1 := StrToFloat(Edit1.Text);
x2 := StrToFloat(Edit2.Text);
ShowMessage(FloatToStr(mMul(x1,x2)));
end;
procedure TFrmDLL.Button4Click(Sender: TObject);
var
x1, x2 : Double;
begin
x1 := StrToFloat(Edit1.Text);
x2 := StrToFloat(Edit2.Text);
ShowMessage(FloatToStr(mDiv(x1,x2)));
end;
procedure TFrmDLL.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
end.
Este formulario es
instanciado en el Procedure ShowForm Exportado en el DLL anterior.
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
procedure ShowForm; StdCall; External 'DLLForm';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowForm;
end;
end.
El código anterior declara una referencia al procedure
ShowForm del DLL anterior e invoca una llamada al mismo.
Revisa estos links:
Todo el código anterior este disponible en el link:
http://terawiki.clubdelphi.com/Delph...orm_in_DLL.rar
Espero sea útil
Nelson.