unit Unit2;
interface
uses
Classes, StdCtrls, SysUtils, Windows, Messages, Dialogs;
const
WM_IN = WM_USER + 1;
WM_OUT = WM_USER + 2;
type
TMyThread = class(TThread)
private
num : integer;
Lb1 : TLabel;
//hd : THandle;
procedure Download;
//procedure DoVisible;
//procedure showVisible(Lbt: TLAbel; B: Integer);
{ Private declarations }
protected
procedure calculate(A: Integer); virtual; abstract;
procedure Execute; override;
public
constructor Create(lbc: TLabel; fund_name : string; sn:integer);
end;
TinFund = class(TMyThread)
protected
procedure calculate(C : Integer); override;
end;
ToutFund = class(TMyThread)
protected
procedure calculate(C : Integer); override;
end;
implementation
uses Unit1;
constructor TMyThread.Create(lbc: TLabel; fund_name : string; sn:integer);
begin
//idhttp去抓sl
//Lb1 := TLabel.Create(nil);
num := sn;
Lb1 := lbc;
//hd:=hhd;
FreeOnTerminate := True;
inherited Create(False);
end;
{
procedure TMyThread.DoVisible;
begin
Lb1.caption := inttostr(num);
end;
procedure TMyThread.showVisible(Lbt: TLAbel; B : Integer);
begin
Lb1 := Lbt;
num := B;
Synchronize(DoVisible);
end;
}
procedure ToutFund.calculate(C : Integer);
var
i : integer;
begin
for i:=1 to C do
begin
//PostMessage(hd,WM_OUT,i,0);
//if Terminated then Exit;
if Assigned(Lb1) then
Lb1.caption := inttostr(i);
end;
ShowMessage('kobe');
end;
procedure TinFund.calculate(C : Integer);
var
i : integer;
begin
for i:=1 to 5000 do
begin
//if Terminated then Exit;
if Assigned(Lb1) then
Lb1.caption := inttostr(i);
//PostMessage(hd,WM_IN,i,0);
end;
end;
procedure TMyThread.Execute;
begin
Download;
calculate(num);
{ Place thread code here }
end;
procedure TMyThread.Download;
begin
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
Edit2: TEdit;
Label2: TLabel;
ApplicationEvents1: TApplicationEvents;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
private
ThreadsRunning : integer;
procedure ThreadDoe(Sender: TObject);
procedure ThreadDoe1(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.ThreadDoe(Sender: TObject);
begin
Dec(ThreadsRunning); //減到為0又可以可以重跑
if ThreadsRunning = 0 then
begin
Button1.Enabled := True; //Thread跑完後
Button2.Enabled := True; //Thread跑完後
end;
end;
procedure TForm1.ThreadDoe1(Sender: TObject);
begin
//Dec(ThreadsRunning); //減到為0又可以可以重跑
Button2.Enabled := True; //Thread跑完後
end;
procedure TForm1.Button1Click(Sender: TObject);
var
fund_name : string;
sn : integer;
begin
ThreadsRunning := 2;//2個Thread會同時跑
button1.enabled:=false;
//TDownLoad.Create.OnTerminate := ThreadDoe;
fund_name := 'kobe1';
sn := 100000;
TinFund.Create(Label1, fund_name, sn).OnTerminate := ThreadDoe;
button2.enabled:=false;
sn := 500000;
ToutFund.Create(Label2, fund_name, sn).OnTerminate := ThreadDoe;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
fund_name : string;
sn : integer;
begin
button2.enabled:=false;
sn := 5000000;
ToutFund.Create(Label2, fund_name, sn).OnTerminate := ThreadDoe1;
end;
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
{
if Msg.message = WM_IN then
Label1.Caption:=IntToStr(Msg.wParam);
if Msg.message = WM_OUt then
Label2.Caption:=IntToStr(Msg.wParam);
}
end;
end.
1 則留言:
They can also offer a decorative element to the room.
There are numerous alternatives of mild fixtures to pick out and all of
them come with trendy and decorative styles.
These use incandescent bulbs for a soft warm light.
Feel free to visit my site ... http://wiki.free-community.in/
張貼留言