Hi again, the GetMem call is correct, it was just a "misprint" from me.
The rest of the code looks like this, please note that I have left out the declaration of variables and some other irrelevant code:
ZIPOptions := ZpGetOptions;
ZIPOptions.Date := nil;
ZIPOptions.szRootDir := nil;
ZIPOptions.szTempDir := nil;
ZIPOptions.fJunkDir := true;
ZIPOptions.fLevel := '9';
ZpSetOptions(ZIPOptions);
oFiles := TStringList.create;
for iIx := 0 To livUtkorg.Items.Count - 1 do
begin
oFiles.Add(livUtkorg.Items[iIx].SubItems[0] + livUtkorg.Items[iIx].Caption);
end;
sTimestamp := FormatDateTime('yyyymmddhhmmss', Date + Time); //Create a unique name for the zip-file
msTempName := 'ABC123_' + sTimestamp + '.zip';
MakeZipFile(msExportPath + msTempName, oFiles);
procedure TGEN990.MakeZipFile(sFileName: String; oFileList: TStrings);
SetDummyInitFunctions(ZUF); //Initialize the dll with dummy functions
ZIPRec.argc := oFileList.Count; //Number of files to zip
GetMem(ZIPRec.lpszZipFN, Length(sFileName) + 1); //Name of zip file - allocate room for null terminated string
ZIPRec.lpszZipFN := StrPCopy(ZIPRec.lpszZipFN, sFileName);
try
GetMem(ZIPRec.FNV, ZIPRec.argc * SizeOf(PChar)); //Dynamic array allocation
FNVStart := ZIPRec.FNV;
try
for iIx := 0 to ZIPRec.argc - 1 do //Copy the file names from FileList to ZipRec.FNV dynamic array
begin
GetMem(ZIPRec.FNV^[iIx], Length(oFileList[iIx]) + 1);
StrPCopy(ZIPRec.FNV^[iIx], oFileList[iIx]);
end;
try
iRC := ZpArchive(ZIPRec); //Send the data to the dll
if iRC <> 0 then
begin
showmessage('An error occurred, errorcode = ' + IntToStr(iRC)); //This is where I get errorcode 12
halt;
end;
finally
ZIPRec.FNV := FNVStart; //Release the memory for the file list
for iIx := (ZIPRec.argc - 1) downto 0 do
begin
FreeMem(ZIPRec.FNV^[iIx], Length(oFileList[iIx]) + 1);
end;
end;
finally
ZIPRec.FNV := FNVStart; //Release the memory for the ZipRec.FNV dynamic array
FreeMem(ZIPRec.FNV, ZIPRec.argc * SizeOf(PChar));
end;
finally
FreeMem(ZIPRec.lpszZipFN, Length(sFileName) + 1); //Release the memory for the FileName
end;
As I said it has worked for many years now using Delphi 2006 but not now using XE! I have also tried to use PAnsiChar around all string variables but unfortunately with the sama result.
Regards,
Kenbla