Help
How can I write an array that was declare in an object? If the array is locally declared there is not problem, it works perfect. However, if the array is part of an object it result in garbage; see below:
Tsi16 = class(Thdr) // signed integer 16b (smallInt)
dta : arraySI16; // dataset
tbl : Tlist; // tables
end;
procedure saveHDFgrid(fNm: pAnsiChar;grd: Tgrid); stdcall;
var
ii : integer;
lyrN : ansiString;
xxx : THDF5Dll;
hFile : hid_t; // file handle (ID)
hDtSp : hid_t; // data space handle (ID)
hDtSt : hid_t; // dataset hadle (ID)
status : herr_t; // hdf calling status
aDim : array of hsize_t; // array dimension specification
ptr : pointer;
hAtt : hid_t;
kk,jj: integer;
xx: array [0…39,0…39] of smallInt;
begin
xxx:= THDF5DLL.Create(extractFilePath(paramStr(0)) + ‘hdf5.dll’);
hFile:= xxx.H5Fcreate(fNm, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
for ii:= 0 to grd.lyr.Count - 1 do begin
// ------------------------------------------------ Create the dataset space
setLength(aDim,2);
aDim[0]:= Thdr(grd.lyr[ii]).gHdr.nRows; // array definition
aDim[1]:= Thdr(grd.lyr[ii]).gHdr.nCols; // array definition
hDtSp:= xxx.H5Screate_simple(2,pHsize_t(@aDim[0]),nil); // data space
// ------------------------------------------------------ Create the dataset
lyrN:= ansiString(Thdr(grd.lyr[ii]).band);
hDtSt:= xxx.H5Dcreate2(hFile,pAnsiChar(lyrN),xxx.H5T_INTEL_I16,hDtSp,H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
// ------------------------------------------------------- Write the dataset
case grd.lyrDT[ii] of
UI08:;
SI16: ptr:= Tsi16(grd.lyr[ii]).dta;
UI16:;
SI32:;
UI32:;
F32 :;
F64 :;
UKN :;
end;
// THIS work PERFECTLY -----------------------------------------------------
for kk:= 0 to 39 do
for jj:= 0 to 39 do
xx[kk,jj]:= kk;
status:= xxx.H5Dwrite(hDtSt,xxx.H5T_INTEL_I16,H5S_ALL,H5S_ALL,H5P_DEFAULT,@xx);
// -------------------------------------------------------------------------
// THIS is NOT working -----------------------------------------------------
status:= xxx.H5Dwrite(hDtSt,xxx.H5T_INTEL_I16,H5S_ALL,H5S_ALL,H5P_DEFAULT,ptr);
// -------------------------------------------------------------------------
// ------------------------------------------------------------------- Close
status:= xxx.H5Dclose(hDtSt); // End access to the dataset and release resources
status:= xxx.H5Sclose(hDtSp); // Terminate access to the data space
status:= xxx.H5Fclose(hFile); // Close the file
end;
end;