![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
Hi Friedns , What is this handle is invalid error (6). , I press the button suspended , but fails after 30 seconds.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, IdAntiFreezeBase, IdAntiFreeze, AdvSmoothProgressBar,
BusinessSkinForm, bsSkinData, bsSkinCtrls;
type
TForm1 = class(TForm)
Button4: TButton;
IdAntiFreeze1: TIdAntiFreeze;
Label13: TLabel;
Label12: TLabel;
Label11: TLabel;
AdvProgressBar1: TAdvSmoothProgressBar;
bsSkinData1: TbsSkinData;
bsCompressedStoredSkin1: TbsCompressedStoredSkin;
bsBusinessSkinForm1: TbsBusinessSkinForm;
Button1: TbsSkinSpeedButton;
Button2: TbsSkinSpeedButton;
button3: TbsSkinSpeedButton;
IdHTTP: TIdHTTP;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure IdHTTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure IdHTTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure bsSkinSpeedButton1Click(Sender: TObject);
procedure bsSkinSpeedButton2Click(Sender: TObject);
procedure bsSkinSpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
f: TFileStream;
success: Boolean;
implementation
uses Unit2;
var
NewThread: TTestThread;
{$R *.DFM}
procedure TForm1.Button4Click(Sender: TObject);
begin
F := TFileStream.Create('dd.exe', fmCreate);
F.Seek(0,soFromEnd);
try
IdHTTP.Get('http://mydezo.com/deneme.exe', F);
except
showmessage('Dosya Bulunamadı');
end;
FreeAndNil(F);
F.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.ProcessMessages;
end;
procedure TForm1.IdHTTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
if AWorkMode = wmRead then
begin
AdvProgressBar1.Position := AWorkCount ;
Label12.Caption := floatToStr(round(advProgressBar1.Position * 100 / advProgressBar1.Maximum)) + ' ' + '%' ; //yüzde
Label13.Caption := IntToStr(AWorkCount div 1024) + ' ';
end;
end;
procedure TForm1.IdHTTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
if AWorkMode = wmRead then
begin
AdvProgressBar1.Maximum := AWorkCountMax ;
AdvProgressBar1.Position := 0 ;
if AWorkCountMax>0 then Label11.Caption:=Inttostr(AWorkCountMax div 1024) + ' ';
end
end;
procedure TForm1.bsSkinSpeedButton1Click(Sender: TObject);
begin
NewThread:=TTestThread.Create(False);
end;
procedure TForm1.bsSkinSpeedButton2Click(Sender: TObject);
begin
Button3.Enabled:=True;
Button2.Enabled:=False;
NewThread.Suspend;
end;
procedure TForm1.bsSkinSpeedButton3Click(Sender: TObject);
begin
Button2.Enabled:=True;
Button3.Enabled:=False;
NewThread.Resume;
end;
end.Код:
unit Unit2;
interface
uses
Classes, Unit1, Windows, Messages, SysUtils;
type
TTestThread = class(TThread)
private
protected
procedure Execute; override;
end;
implementation
procedure TTestThread.Execute;
begin
FreeOnTerminate:=true;
form1.Button4.Click;
end;
end.
please help me friends ![]() Последний раз редактировалось alyamus, 12.02.2014 в 22:57. |
|
#2
|
||||
|
||||
|
use TThread.Synchronize or user message
(Is it better to use TThread's ”Synchronize” or use Window Messages for IPC between main and child thread?) when working with VCL components from child thread |
|
#3
|
|||
|
|||
|
The problem is diferent.
It is in your thread. You created thread and set it to terminate on finish... ...and you do not have loop inside. The main thread procedure (Execute) went to the finish and thread commit the suicide ![]() The code in the thread should look like the following: Код:
procedure TTestThread.Execute;
begin
FreeOnTerminate:=true;
While not Terminated do
begin
form1.Button4.Click;
end;
end; |