[fpc-pascal]Incompatible record alignment?

Gheorghe Stefan BERINDE sberinde at math.ubbcluj.ro
Wed Jan 9 08:43:58 CET 2002


Hello all,

I encounter some difficulties when passing a record variable from
a FPC dynamic link library to a Delphi host program.
I try to align the record structure on 8-bit boundary for Delphi
compatibility, but it does'nt work properly. Do I make mistakes here?
You can test this with the following two little programs:

-------------------------------------------------------
(* FPC Library *)

library lib; {lib.dll}

{$PACKRECORDS 8}
type TVector = record
                x,y,z: extended;
               end;
     TExternalData = record
                      p: array[1..2] of TVector;
                     end;	
{$PACKRECORDS DEFAULT}

procedure DLLProc(var ED:TExternalData); stdcall;
var i: longint;
begin
 for i:=1 to 2 do
 begin
  ED.p[i].x:=1e-1; ED.p[i].y:=1e-2; ED.p[i].z:=1e-3;
 end;
end;

exports DLLProc name 'DLLProc';
end.

-------------------------------------------------------
(* Delphi Program *)

program caller;

{$APPTYPE CONSOLE}

type TVector = record
                x,y,z: extended;
               end;
     TExternalData = record
                      p: array[1..2] of TVector;
                     end;

var ED: TExternalData;
    i : longint;

procedure DLLProc(var ED: TExternalData); stdcall; external 'lib.dll';

begin
 DLLProc(ED);
 for i:=1 to 2 do writeln(ED.p[i].x,' ',ED.p[i].y,' ',ED.p[i].z);
 readln;
end.
-------------------------------------------------------

Thank you in advance,

Stefan






More information about the fpc-pascal mailing list