H
Haicon
Имеется проблема с Thead во врейме. Описываю ситуацию.
Есть форма. На нее ложу кнопку и frame. на врем тоже ложу кнопку. И выполняю одинаковый код. Причем в форме код выполняется коректно. а во фрейме вылетает на ошибке.
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0044ECB9 in module 'Project1.exe'. Write of address 00000224'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Привожу исходник. Помогите кто чем может. Заранее благодарен!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls;
type
TScanThread = class(TThread)
private
procedure IncCount;
protected
procedure Execute; override;
end;
TForm1 = class(TForm)
Frame21: TFrame2;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
ThreadCount: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TScanThread.Execute;
begin
inherited;
Synchronize(IncCount);
end;
procedure TScanThread.IncCount;
begin
Form1.ThreadCount := Form1.ThreadCount + 1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TScanThread.Create(False)
end;
end.
////////////////////////////////////////////////////////////////////////////
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TScanThread = class(TThread)
private
procedure IncCount;
protected
procedure Execute; override;
end;
TFrame2 = class(TFrame)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
ThreadCount: Integer;
public
{ Public declarations }
end;
var
Frame2 : TFrame2;
implementation
{$R *.dfm}
procedure TScanThread.Execute;
begin
inherited;
Synchronize(IncCount);
end;
procedure TScanThread.IncCount;
begin
Frame2.ThreadCount := Frame2.ThreadCount + 1;
end;
procedure TFrame2.Button1Click(Sender: TObject);
begin
TScanThread.Create(False)
end;
end.
Есть форма. На нее ложу кнопку и frame. на врем тоже ложу кнопку. И выполняю одинаковый код. Причем в форме код выполняется коректно. а во фрейме вылетает на ошибке.
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0044ECB9 in module 'Project1.exe'. Write of address 00000224'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Привожу исходник. Помогите кто чем может. Заранее благодарен!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls;
type
TScanThread = class(TThread)
private
procedure IncCount;
protected
procedure Execute; override;
end;
TForm1 = class(TForm)
Frame21: TFrame2;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
ThreadCount: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TScanThread.Execute;
begin
inherited;
Synchronize(IncCount);
end;
procedure TScanThread.IncCount;
begin
Form1.ThreadCount := Form1.ThreadCount + 1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TScanThread.Create(False)
end;
end.
////////////////////////////////////////////////////////////////////////////
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TScanThread = class(TThread)
private
procedure IncCount;
protected
procedure Execute; override;
end;
TFrame2 = class(TFrame)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
ThreadCount: Integer;
public
{ Public declarations }
end;
var
Frame2 : TFrame2;
implementation
{$R *.dfm}
procedure TScanThread.Execute;
begin
inherited;
Synchronize(IncCount);
end;
procedure TScanThread.IncCount;
begin
Frame2.ThreadCount := Frame2.ThreadCount + 1;
end;
procedure TFrame2.Button1Click(Sender: TObject);
begin
TScanThread.Create(False)
end;
end.