Estou fazendo uma aplicação que tem vários forms. Para evitar de escrever várias vezes o código de criação dinâmica de formulários, criei uma dll para que ele faça isso, mas quando vou executar o programa, dá um erro e não permite executar o programa.
O código da DLL que eu criei é o seguinte:
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Controls,
Forms,
Dialogs,
Menus,
ExtCtrls,
ComCtrls;
{$R *.res}
function AbreForm(a : TFormClass; b : TForm) : TFormClass;Export;stdcall;
begin
Application.CreateForm(a,b);
b.ShowModal;
b.Free;
b := nil;
end;
begin
end.
O código do Formulário Principal que chama a Dll é o seguinte:
unit UntPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFrmPrincipal = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function AbreForm(a : TFormClass; b : TForm) :String;stdcall;
var
FrmPrincipal: TFrmPrincipal;
implementation
uses Unt2;
function AbreForm(a : TFormClass; b : TForm) : String;external 'OpenForm.dll'
{$R *.dfm}
procedure TFrmPrincipal.Button1Click(Sender: TObject);
begin
[b]AbreForm(TFrm2,Frm2);[/b]
end;
end.
Aí quando compilo o projeto aparece um erro de endereçamento de memória. Alguém pode me ajudar como solucionar esse erro???
Pergunta
Guest Dionísio Júnior
Estou fazendo uma aplicação que tem vários forms. Para evitar de escrever várias vezes o código de criação dinâmica de formulários, criei uma dll para que ele faça isso, mas quando vou executar o programa, dá um erro e não permite executar o programa.
O código da DLL que eu criei é o seguinte:
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, Dialogs, Menus, ExtCtrls, ComCtrls; {$R *.res} function AbreForm(a : TFormClass; b : TForm) : TFormClass;Export;stdcall; begin Application.CreateForm(a,b); b.ShowModal; b.Free; b := nil; end; begin end.O código do Formulário Principal que chama a Dll é o seguinte:unit UntPrincipal; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFrmPrincipal = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; function AbreForm(a : TFormClass; b : TForm) :String;stdcall; var FrmPrincipal: TFrmPrincipal; implementation uses Unt2; function AbreForm(a : TFormClass; b : TForm) : String;external 'OpenForm.dll' {$R *.dfm} procedure TFrmPrincipal.Button1Click(Sender: TObject); begin [b]AbreForm(TFrm2,Frm2);[/b] end; end.Aí quando compilo o projeto aparece um erro de endereçamento de memória. Alguém pode me ajudar como solucionar esse erro???
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.