首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解压zip文件时,Android应用程序没有响应

解压zip文件时,Android应用程序没有响应
EN

Stack Overflow用户
提问于 2019-01-07 16:37:51
回答 1查看 152关注 0票数 2

我想通过FMX Android应用程序提取较大的zip文件,但Android看到该应用程序没有响应,建议将其删除。

下面是我的代码:

代码语言:javascript
复制
procedure AddSoundRes(SfileN: string);
begin
  if trim(SfileN) = '' then ShowMessage('Please Select A File')
  else
    begin
      try
        FormMessage.Show;
        Application.ProcessMessages;
        Archive2 := TZipFile.Create;
        Archive2.Open(SfileN, zmRead);
        Archive2.ExtractZipFile(SfileN, soundpath);
        ShowMessage('Resource added successfully');
      finally
        Archive2.Free;
        FormMessage.Hide;
      end;
    end;
end;

如何解决?

EN

回答 1

Stack Overflow用户

发布于 2019-01-07 20:28:35

您需要在另一个线程中执行此操作。当所有这些都在同一个线程中完成时,您不能执行如此长的任务并期望UI可用。

下面是我给你做的一个例子:

代码语言:javascript
复制
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation,
  FMX.StdCtrls, System.Zip;

type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TExtractZip = class(TThread)
  private
    fZIP: string;
  protected
    procedure Execute; override;
  public
    constructor Create(const aZipFile: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TExtractZip }

constructor TExtractZip.Create(const aZipFile: string);
begin
  inherited Create(True);
  FreeOnTerminate := True;
  fZIP := aZipFile;
end;

procedure TExtractZip.Execute;
begin
  if TZipFile.IsValid(fZIP) then
    TZipFile.ExtractZipFile(fZIP, '.\contents\');
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  extractzip: TExtractZip;
begin
  extractzip := TExtractZip.Create('.\azipfile.zip');
  extractzip.Start;
end;

end.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54070934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档