Dúvidas com DLL

Delphi

12/09/2005

Olá;



Criei a DLL abaixo mas não consigo descobrir o erro na linha em negrito.



library CPKG;



uses

SysUtils,

Classes,

Windows,

Forms;



function oForm(nClasse: String): Boolean; stdcall;



{$R *.res}



function pForm(nFile: String; nClasse: String): Boolean; stdcall; // Criar um pacote

var

aPackage : Array of Cardinal;

aPersistentClass: TPersistentClass;

aForm : TForm;

I : Integer;

begin

SetLength(aPackage,0);

If(FileExists(nFile)) Then

begin

SetLength(aPackage,Length(aPackage) + 1);

aPackage[Length(aPackage) - 1] := LoadPackage(nFile);

result := True;

oForm(nClasse);

end

else

result := False;

end;



function oForm(nClasse: String): Boolean; stdcall; // Abrir um formulário do pacote

var

aPersistentClass: TPersistentClass;

aForm : TForm;

begin

aPersistentClass := GetClass(nClasse);

If(aPersistentClass = nil) Then

begin

// showmessage(´err´);

result := False;

end

else

begin

aForm := TComponentClass(aPersistentClass).Create(Application) as TForm;

AForm.Show;

end;

end;



[b:8e172b2f57]exports[/b:8e172b2f57]
oForm;



begin

end.





Msg de erro: Expected Begin but Exports at line 60.



Outra dúvida como faço pra chamar um DLL externa de dentro de outra.



Valeu.


Excon

Excon

Curtidas 0

Respostas

Celamar

Celamar

12/09/2005

Tente deixar seu exports depois de todo o seu código, deixe o antes do end, se eu não me engano ele tem que ser depois de todo o código.


GOSTEI 0
Ipc$

Ipc$

12/09/2005

Tente definir a função:
function oForm(nClasse: String): Boolean; stdcall; forward;
Vc está utilizando String como parâmetro, então vc deve colocar ShareMem como primeira linha do [b:98ba5b34db]uses[/b:98ba5b34db] da dll e dos
.dpr dos programas que a chamam; senão defina o parâmetro como PChar.


GOSTEI 0
Michelli88

Michelli88

12/09/2005

Voce ta declarando a função:
library CPKG; uses SysUtils, Classes, Windows, Forms; [b:b98977cc12]function oForm(nClasse: String): Boolean; stdcall;[/b:b98977cc12] {$R *.res} function pForm(nFile: String; nClasse: String): Boolean; stdcall; // Criar um pacote var aPackage : Array of Cardinal; aPersistentClass: TPersistentClass; aForm : TForm; I : Integer; begin [b:b98977cc12]...[/b:b98977cc12]


[b:b98977cc12]NAO PRECISA![/b:b98977cc12]

library CPKG;

uses
  SysUtils,
  Classes,
  Windows,
  Forms;

{$R *.res}

function pForm(nFile: String; nClasse: String): Boolean; stdcall; // Criar um pacote
var

  aPackage : Array of Cardinal;
  aPersistentClass: TPersistentClass;
  aForm : TForm;
  I : Integer;
begin
  SetLength(aPackage,0);
  If(FileExists(nFile)) Then begin
    SetLength(aPackage,Length(aPackage) + 1);
    aPackage[Length(aPackage) - 1] := LoadPackage(nFile);
    result := True;
    oForm(nClasse);
  end
  else result := False;
end;

function oForm(nClasse: String): Boolean; stdcall; // Abrir um formulário do pacote
var
  aPersistentClass: TPersistentClass;
  aForm : TForm;
begin
  aPersistentClass := GetClass(nClasse);
  If(aPersistentClass = nil) Then begin
    result := False;
  end
  else begin
    aForm := TComponentClass(aPersistentClass).Create(Application) as TForm;
    AForm.Show;
  end;
end;

exports
  oForm,  pForm;

begin
end.



GOSTEI 0
Ipc$

Ipc$

12/09/2005

Pode suprimir a declaração da função, mas como pForm chama oForm, oForm deve vir antes de pForm.


GOSTEI 0
POSTAR