Hi All,

I have written a little library in C (compiled in as a DLL) to use it in Free Pascal and Delphi applications. While the code (below) works with Delphi (7), I get an Access Violation using FPC (1.98). Perhaps I am missing something.
Any hint? Thanks!


program fpc_dll;
{$H+}{$MODE OBJFPC}

uses
 sysutils;

type
myarray = array of double;
// if I declare "myarray = array[0..9] of double;" the code runs as expected.


function get_array(a, b: myarray; size: integer; value: double): integer; cdecl; external 'mylib.dll';
// extern "C" __cdecl __declspec(dllexport) int get_array(double a[], double b[], int size, double val);


var
 x, y, z: double;
 t: integer;
 i, kk, qq: integer;
 mat1, mat2: pmyarray;
 st: string;
begin
 kk := 10;
 SetLength(mat1,kk);
 SetLength(mat2,kk);
 for i := 0 to kk-1 do
 begin
   mat1[i] := i+1;
   st := FloatToStr(mat1[i]);
   writeln(st);
 end;
 qq := get_array(mat1,mat2,kk,3.14);
 st := IntToStr(qq);
 writeln(st);
 for i := 0 to kk-1 do
 begin
   st := FloatToStr(mat1[i]);
   writeln(st);
 end;
 st := '------------------------------';
 writeln(st);
 for i := 0 to kk-1 do
 begin
   st := FloatToStr(mat2[i]);
   writeln(st);
 end;

 SetLength(mat1,0);
 SetLength(mat2,0);
end.

jk

--
// Jilani KHALDI
*** K-Book
Interactive Scientific & Technical Pubblications
http://jkhaldi.oltrelinux.com


_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to