View Issue Details

IDProjectCategoryView StatusLast Update
0006581JEDI Code LibraryJclCompressionpublic2019-06-15 16:29
Reporterbaka0815Assigned To 
PrioritynormalSeveritycrashReproducibilityalways
Status newResolutionopen 
Product VersionVersion 2.5 (Subversion repository/Daily zips) 
Target VersionFixed in Version 
Summary0006581: Compress ZIP files with OnProgress event
DescriptionWe're trying to compress multiple files into a ZIP file using JclCompression.

When we attach an OnProgress event the process freezes.

In the attached example we're tying to add a line to a TMemo in the OnProgress event. This does not work and the message "OnCompress() Beginn" is never displayed in the TMemo.

Here is the code of the GetCount() method which is called in the Lines.Add() method:

---8<--- Vcl.StdCtrls ---
function TMemoStrings.GetCount: Integer;
begin
  Result := 0;
{$IF DEFINED(CLR)}
  if Memo.HandleAllocated or (Memo.WindowText <> '') then
{$ELSE}
  if Memo.HandleAllocated or (Memo.WindowText <> nil) then
{$ENDIF}
  begin
    Result := SendMessage(Memo.Handle, EM_GETLINECOUNT, 0, 0); // <-- hangs on this line
    if SendMessage(Memo.Handle, EM_LINELENGTH, SendMessage(Memo.Handle,
      EM_LINEINDEX, Result - 1, 0), 0) = 0 then Dec(Result);
  end;
end;
--- Vcl.StdCtrls--->8---

The process hangs when it tries to send a message to the Memo.Handle.

When we remove the Memo.Lines.Add() the process hangs on the following line while trying to set the new progress:

---8<--- Vcl.ComCtrls ---
procedure TProgressBar.SetPosition(Value: Integer);
begin
  if not F32BitMode and ((Value < 0) or (Value > Limit16)) then
    ProgressLimitError;
  if HandleAllocated then
    SendMessage(Handle, PBM_SETPOS, Value, 0) // <-- hangs on this line
  else
    FPosition := Value;
end;
--- Vcl.ComCtrls --->8---

There are some different things to create the ZIP file correctly
* removing the OnProgress event
* add only one file
* setting the compression method to cmCopy
* compressing as a 7z file

However we need to compress multiple files, compress them and it has to be a ZIP file.
Additional InformationDelphi: 10.1 Berlin Update 2
JCL: current git (e167f07a1c57cf7304bf38f982fce19bcc62a3a1 on Apr 9, 2017)
7z.dll: 4.62, 4.65, 9.20, 9.38, 16.04 and 17.00
TagsNo tags attached.
Fixed in revision
IDE versionDelphi/C++Builder XE3

Activities

2017-07-19 10:09

 

example.zip (53,924 bytes)

baka0815

2017-09-01 17:01

reporter   ~0021434

One and a half month no change - is anyone still reading this?

baka0815

2017-09-13 10:10

reporter   ~0021435

Ok, it looks like it's some locking problem.

What we're now doing is to compress in a thread (or a task):

---8<--- Code ---
      Task := TTask.Create(
        procedure
        begin
          Archive.Compress;
        end);
      Task := Task.Start;

      while (Task.Status in [TTaskStatus.WaitingToRun, TTaskStatus.Running]) do
      begin
        Application.ProcessMessages;
      end;
--->8--- Code ---

This works for us.
However this locking is not the case while decompression a ZIP file or compressing a 7z file.

Is this a bug inside the 7z.dll?

mh

2019-04-14 12:08

reporter   ~0021690

Is it necessary to use SendMessage instead of PostMessage? I'm asking because SendMessage blocks the caller until the message has been processed and if the receiver for the message doesn't have working message processing at that particular point in time it could block the caller endlessly.

baka0815

2019-05-10 18:20

reporter   ~0021821

Well, as you can see the SendMessage() is in the Delphi Vcl-Code not in our code, so there is nothing we can do about.
However it's weird that it's working with the settings I mentioned (compressing only 1 file, not compressing, ...).

mh

2019-06-15 16:29

reporter   ~0021863

What happens if the code in the OnProgress Method is put into something like synchronize? Mabye it needs to run in the context of the main thread?

Issue History

Date Modified Username Field Change
2017-07-19 10:09 baka0815 New Issue
2017-07-19 10:09 baka0815 File Added: example.zip
2017-07-19 10:09 baka0815 IDE version => Delphi/C++Builder XE3
2017-09-01 17:01 baka0815 Note Added: 0021434
2017-09-13 10:10 baka0815 Note Added: 0021435
2019-04-14 12:08 mh Note Added: 0021690
2019-05-10 18:20 baka0815 Note Added: 0021821
2019-06-15 16:29 mh Note Added: 0021863