아래의 소스를 좀 더 간략하게 하고픈데여..
완전히 팍 줄일 수 있는 방법이 있을꺼 같은데...
방법을 잘 모르겠습니다...
그리구 아래처럼 하니까.. 쫌 이상하더라구여... ㅜ.ㅜ
느려진다던가... 메세지창이 제때 안뜬다던가하는....
쓰레드에 관한건데여...
도와주세여...
function ThreadFunc : integer ; stdcall;
var I : integer;
begin
for i := 0 to 100000 do
begin
Form1.labData1.Caption := IntToStr(i);
end;
end;
function ThreadFunc2 : integer ; stdcall;
var I : integer;
begin
for i := 0 to 100000 do
begin
Form1.labData2.Caption := IntToStr(i);
end;
end;
function ThreadFunc3 : integer ; stdcall;
var I : integer;
begin
for i := 0 to 100000 do
begin
Form1.labData3.Caption := IntToStr(i);
end;
end;
function ThreadFunc4 : integer ; stdcall;
var I : integer;
begin
for i := 0 to 100000 do
begin
Form1.labData4.Caption := IntToStr(i);
end;
end;
function ThreadFunc5 : integer ; stdcall;
var I : integer;
begin
for i := 0 to 100000 do
begin
Form1.labData5.Caption := IntToStr(i);
end;
end;
procedure TForm1.btnMessageClick(Sender: TObject);
begin
ShowMessage('내가 보여?');
end;
procedure TForm1.btnStart1Click(Sender: TObject);
var tmpbtn : TButton;
ThreadID : DWord;
stag : string;
Dur : integer;
begin
CreateThread(nil,0,@ThreadFunc,nil,0,ThreadID);
end;
procedure TForm1.btnStart2Click(Sender: TObject);
var ThreadID : DWord;
begin
CreateThread(nil,0,@ThreadFunc2,nil,0,ThreadID);
end;
procedure TForm1.btnStart3Click(Sender: TObject);
var ThreadID : DWord;
begin
CreateThread(nil,0,@ThreadFunc3,nil,0,ThreadID);
end;
procedure TForm1.btnStart4Click(Sender: TObject);
var ThreadID : DWord;
begin
CreateThread(nil,0,@ThreadFunc4,nil,0,ThreadID);
end;
procedure TForm1.btnStart5Click(Sender: TObject);
var ThreadID : DWord;
begin
CreateThread(nil,0,@ThreadFunc5,nil,0,ThreadID);
end;
type
TLabelThread = class(TThread)
private
FTarget :TLabel;
protected
procedure Execute;override;
public
constructor Create(a_Target:TLabel);override;
end;
implementation
constructor TLabelThread .Create(a_Target:TLabel);
begin
inherited Create(TRUE);
FTarget := a_Target;
FreeOnTerminate := TRUE;
Resume;
end;
procedure TLabelThread.Execute;
var
I : integer;
begin
if not Assigned(FTarget) then exit;
for i := 0 to 100000 do begin
FTarget.Caption := IntToStr(i);
Sleep(10); // <-- 요거이 꼭 필요할 듯 합다...
end;
end;
-------------------------
procedure TForm1.btnStart1Click(Sender: TObject);
begin
TLabelThread.Create(labData1).Create();
end;
procedure TForm1.btnStart2Click(Sender: TObject);
begin
TLabelThread.Create(labData2).Create();
end;
procedure TForm1.btnStart3Click(Sender: TObject);
begin
TLabelThread.Create(labData3).Create();
end;
procedure TForm1.btnStart4Click(Sender: TObject);
begin
TLabelThread.Create(labData4).Create();
end;
procedure TForm1.btnStart5Click(Sender: TObject);
begin
TLabelThread.Create(labData5).Create();
end;
호접 얼큰이었음다.. 꾸뻑 (__)