Einzelnen Beitrag anzeigen

DCoderHH

Registriert seit: 4. Feb 2015
Ort: Hamburg
84 Beiträge
 
Delphi 10 Seattle Professional
 
#1

C-Array/Struct nach Delphi konvertieren

  Alt 4. Feb 2015, 13:14
Delphi-Version: 5
Hallo alle zusammen,

ich habe eine C-DLL, die ich in Delphi nutzen möchte. Die Funktionen, die ich aufrufen möchte, habe ich schon nach Delphi übersetzt. Einer Funktion muss die folgende struct übergeben werden. Diese nach Delphi zu konvertieren klappt nicht. Es gibt eine Schutzverletzung "access violation at 0x772d0097: read of address 0x33363143"

Original C-Code:

Code:
struct s_group21diag
{
   char scode[6];
   char slokal[2];
};

struct s_group21
{
   char sgrpv[8];
   short ndiag; //Anzahl der Elemente im nachfolgenden Array
   struct s_group21diag * adiag; //Zeiger auf ein Array das mehere s_group21diag enthält
}
Meine Übersetzung nach Delphi:

Delphi-Quellcode:
type

TGroup21Diag = record
  scode: array [0 .. 5] of AnsiChar;
  slokal: array [0 .. 1] of AnsiChar;
end;
PGroup21Diag = ^TGroup21Diag;

TGroup21 = record
  sgrpv: array [0 .. 7] of AnsiChar;
  ndiag: SmallInt;
  adiag: array of PGroup21Diag;
end;
PGroup21 = ^TGroup21;
Ist adiag richtig dekaliert?

Delphi-Quellcode:
procedure Test;
begin
  New(Group21); //reicht das aus?
  EinlesenAusDatei(Group21);

  if Group21.ndiag > 0 then
    showmessage(Group21.adiag[0].scode); //Schutzverletzung hier!

  Dispose(Group21)
end;
Danke und viele Grüße!
  Mit Zitat antworten Zitat