Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:44:34+00:00 2026-05-23T03:44:34+00:00

//Thread Procedure StartUpdating.UnZip; begin form2.ZipForge1.FileName := ItemToExtract; form2.ZipForge1.OpenArchive; form2.ZipForge1.BaseDir := XXX; form2.ZipForge1.ExtractFiles(‘*.*’); form2.ZipForge1.CloseArchive; end;

  • 0
//Thread
Procedure StartUpdating.UnZip;
begin
form2.ZipForge1.FileName := ItemToExtract;
form2.ZipForge1.OpenArchive;
form2.ZipForge1.BaseDir := XXX;
form2.ZipForge1.ExtractFiles('*.*');
form2.ZipForge1.CloseArchive;
end;

PROCEDURE StartUpdating.Execute;
begin
UnZip; // on ZipForge1Password I get error: EInvalidOperation with message 'Canvas does not allow drawing'. The Form is not frozen while archive is being extracted.
Synchronize(UnZip); //  No EInvalidOperation error on ZipForge1Password, but the Form is frozen while archive is being extracted.
end;

procedure TForm2.ZipForge1Password(Sender: TObject; FileName: string;
  var NewPassword: AnsiString; var SkipFile: Boolean);
var  s:string;
begin

if PassSkip then SkipFile:=true else
    begin
    if InputQuery('Pass',FileName, s) then NewPassword:=ansistring(s) else //I suppose EInvalidOperation error is here
        begin
          PassSkip:=true;
          SkipFile:=true;
          ThreadUpdating.Terminate;
        end;
    end;
end;

How can I unzip without frozen form and without EInvalidOperation error? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:44:35+00:00Added an answer on May 23, 2026 at 3:44 am

    UnZip; // on ZipForge1Password I get error: EInvalidOperation with message 'Canvas does not allow drawing'. The Form is not frozen while archive is being extracted.

    This is because you run thread unsafe code (1) from within your thread. All thread unsafe code (1) (like most VCL and WinAPI routines) has to run in the main thread. The UnZip routine references form2, which is a VCL component, so you must (1) use Synchronize to temporarily transfer execution to the main thread.

    Synchronize(UnZip); // No EInvalidOperation error on ZipForge1Password, but the Form is frozen while archive is being extracted.

    As explained, with Synchronize you deliberately execute code in the main thread, hence it seems to be frozen during the extraction process.

    So now you have a little chicken-and-egg-dilemma. One which could be eliminated by creating the ZipForge component @runtime in your thread. In that case, the only user interaction that remains being synchronized is providing a password. The downside is that Synchronize only takes a parameterless method, so you have to do a little work for implementing the OnPassword event handler. It cóuld look like the following:

    type
      TUnZip = class(TThread)
      private
        FFileName: String;
        FPassword: AnsiString;
        FSkipFile: Boolean;
        procedure DoPassword;
        procedure ZipForgePassword(Sender: TObject; FileName: string;
          var NewPassword: AnsiString; var SkipFile: Boolean);
      protected
        procedure Execute; override;
      public
        property PassSkip ...
        property ItemToExtract ...
      end;
    
    { TUnZip }
    
    procedure TUnZip.DoPassword;
    var
      S: String;
    begin
      if PassSkip then
        FSkipFile := True
      else if InputQuery('Pass', FFileName, S) then
        FPassword := AnsiString(S)
      else
      begin
        PassSkip := True;
        FSkipFile := True;
        Terminate;
      end;
    end;
    
    procedure TUnZip.Execute;
    var
      ZipForge: TZipForge;
    begin
      ZipForge := TZipForge.Create(...);
      try
        ZipForge.OnPassword := ZipForgePassword;
        ZipForge.FileName := ItemToExtract;
        ZipForge.OpenArchive;
        if not Terminated then  {Assuming OpenArchive triggers the OnPassword event}
        begin
          ZipForge.BaseDir := XXX;
          ZipForge.ExtractFiles('*.*');
          ZipForge.CloseArchive;
        end;
      finally
        ZipForge.Free;
      end;
    end;
    
    procedure TUnZip.ZipForgePassword(Sender: TObject; FileName: String;
      var NewPassword: AnsiString; var SkipFile: Boolean);
    begin
      FFileName := FileName;
      FPassword := NewPassword;
      FSkipFile := SkipFile;
      Synchronize(DoPassword);
      FileName := FFileName;
      NewPassword := FPassword;
      SkipFile := FSkipFile;
    end;
    

    Disclaimer: I am unfamiliar with the ZipForge component so this code can be incomplete. You should implement all designtime generated settings in TUnZip.Execute. I even don’t know if TZipForge has an OnPassword event at all, but I made that up from your code.

    Edit:

    (1) Not all code of the VCL is thread unsafe, and it is not said that every call from within a secundary thread to a main thread control, component or variable is dangerous, but it is good practice to prevent it. To me, the term thread safety is comfortably cautionary. But the actual reason for this unsafety is that all user interface controls (i.e. all windows GDI objects) can only have affinity to a single thread; the main thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I examined about stack unwinding on thread procedure in win32 environment. My test code
There is a stored procedure: CREATE PROCEDURE [dbo].[TestProc] AS BEGIN SET NOCOUNT ON; create
I'm using the TIdHTTP.Get procedure in a thread to download a file . My
I've seen a number of examples that have a thread procedure that looks like
I am creating a thread using BeginThread. In the procedure I am using to
Thread thread = new Thread(new Runnable() { @Override public void run() { try {
thread.join() will call thread.wait() , but who and when notifies (either with thread.notify() or
Can Thread.Abort interrupt a thread that is sleeping (using, say, Thread.Sleep(TimeSpan.FromDays(40)) ? Or will
This thread didn't helped me. If I use $class_vars = get_class_vars(get_class($this)); foreach ($class_vars as
If a Thread creates a daemon Thread, can I rely on the fact that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.