【发布时间】:2016-04-17 16:38:18
【问题描述】:
我正在尝试在示例项目中创建一个线程,但这里引发了一个异常是示例项目代码
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TURLDownload = class(TThread)
private
FURL: String;
Fnameofimg: string;
FPathImage: string;
FFileNameImage: string;
// Internal //
ImageName: string;
PathURL: string;
protected
procedure Execute; override;
public
constructor Create(const AUrl: String; Const AOutPathImages: string;
Anameofimg: String); reintroduce;
destructor Destroy; override;
property URL: string read FURL write FURL;
property PathImage: string read FPathImage;
property FileNameImage: string read FFileNameImage;
end;
var
Form1: TForm1;
th: TURLDownload;
implementation
{$R *.dfm}
{ TURLDownload }
procedure TURLDownload.reached;
begin
showmessage('done');
end;
constructor TURLDownload.Create(const AUrl, AOutPathImages: string;
Anameofimg: String);
begin
inherited Create(False);
FreeOnTerminate := True;
FURL := AUrl;
Fnameofimg := Anameofimg;
FPathImage := AOutPathImages;
end;
destructor TURLDownload.Destroy;
begin
inherited;
end;
procedure TURLDownload.Execute;
begin
synchronize(reached);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
th.Create('jgvjk', 'ngkj', 'jkgfjk');
end;
end.
当我点击 button1 开始创建线程时,我遇到了这个异常消息
$004C0384 第一次机会例外。异常类 $C0000005 与 消息“0x004c0384 处的访问冲突:读取地址 0x0000003c”。 处理 Project1.exe (4060)
然后当我单击中断时,它会将我返回到在此代码处创建的线程内的系统类文件
FSuspended := not FExternalThread;
我做错了什么?我正在使用 Delphi xe7
【问题讨论】:
标签: multithreading delphi delphi-xe7