elmago00,
Cita:
Empezado por elmago00
...algún experto en dll, que me pueda dar un pequeñísimo ejemplo de dll...
|
No soy un experto en Delphi, pero tratare de ayudar lo mejor que pueda
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)
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
TA1 = Array of String;
TA2 = Array of Integer;
TA3 = Array of Double;
function FA1(Value : String) : TA1; stdcall; external 'TestDLL.dll';
function FA2(Value : String) : TA2; stdcall; external 'TestDLL.dll';
function FA3(Value : String) : TA3; stdcall; external 'TestDLL.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
function StringToCaseSelect(Selector : string; CaseList: array of string): Integer;
var
pos: integer;
begin
Result := -1;
for pos := 0 to Length(CaseList)-1 do
begin
if CompareText(Selector, CaseList[pos]) = 0 then
begin
Result := pos;
Break;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
A1 : TA1;
A2 : TA2;
A3 : TA3;
i : Integer;
begin
case StringToCaseSelect(Edit1.Text,['A1','A2','A3']) of
0 : A1 := FA1(Edit1.Text);
1 : A2 := FA2(Edit1.Text);
2 : A3 := FA3(Edit1.Text);
else
MessageDlg('Solo se permiten los valores string A1, A2 y A3', mtInformation, [mbOK], 0);
end;
Memo1.Clear;
if Length(A1) > 0 then
for i := Low(A1) to High(A1) do
Memo1.Lines.Add(A1[i]);
if Length(A2) > 0 then
for i := Low(A2) to High(A2) do
Memo1.Lines.Add(IntToStr(A2[i]));
if Length(A3) > 0 then
for i := Low(A3) to High(A3) do
Memo1.Lines.Add(FloatToStr(A3[i]));
end;
end.
El código anterior en Delphi 2010 bajo Windows 7 Professional x32,
implementa tres funciones exportadas por un DLL en un programa tipo Desktop bajo Windows.
Revisa este código:
Código Delphi
[-]
library TestDLL;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TA1 = Array of String;
TA2 = Array of Integer;
TA3 = Array of Double;
{$R *.res}
function FA1(Value : String) : TA1; stdcall;
var
A1 : TA1;
i : Integer;
begin
if Value = 'A1' then
begin
SetLength(A1,10);
Randomize;
for i := 0 to 9 do
A1[i] := 'Number-' + IntToStr(Random(100));
Result := A1;
end
else
begin
SetLength(A1,1);
A1[0] := 'La función esperaba A1 como string y recibio : ' + Value;
Result := A1;
end;
end;
function FA2(Value : String) : TA2; stdcall;
var
A2 : TA2;
i : Integer;
begin
if Value = 'A2' then
begin
SetLength(A2,10);
Randomize;
for i := 0 to 9 do
A2[i] := Random(100);
Result := A2;
end
else
begin
SetLength(A2,1);
A2[0] := High(Integer);
Result := A2;
end;
end;
function FA3(Value : String) : TA3; stdcall;
var
A3 : TA3;
i : Integer;
begin
if Value = 'A3' then
begin
SetLength(A3,10);
Randomize;
for i := 0 to 9 do
A3[i] := Random;
Result := A3;
end
else
begin
SetLength(A3,1);
A3[0] := 3.1415927;
Result := A3;
end;
end;
exports
FA1, FA2, FA3;
begin
end.
El código anterior en Delphi 2010 bajo Windows 7 Professional x32,
implementa un DLL que exporta tres funciones en la cual cada una devolverá un array en función del string de entrada, en caso de que el string recibido no sea el correcto se devuelve un valor por defecto.
Nota: Los códigos anteriores funcionan correctamente en una Máquina Física con
Delphi 2010 bajo Windows 7 Professional x32 y en una Máquina Virtual con
Delphi XE4 bajo Windows 7 Professional x32,
si el evento que describes se repite nuevamente con el ejemplo propuesto, te sugiero revisar la instalación de Delphi XE3 y en caso contrario la aplicación y dll en cuestión..
Espero sea útil
Nelson.