Ver Mensaje Individual
  #2  
Antiguo 26-11-2004
Avatar de OSKR
OSKR OSKR is offline
Miembro
 
Registrado: nov 2004
Ubicación: San Cristóbal/Táchira/Venezuela
Posts: 389
Reputación: 20
OSKR Va por buen camino
Una manera stándar de usar hilos es de la foma API de GUINDOWS
#include <vcl.h>
#pragma hdrstop
//#include "ThreadFormUnit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
HANDLE Thread;

DWORD WINAPI ThreadFunc(LPVOID Param)
{ int i=0;
while(true)
{ Form1->Label1->Caption=IntToStr(i);
Sleep(100);
i++;
}
}

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{ randomize();
DWORD Id;
Thread = CreateThread(0, 0, ThreadFunc,
Form1->Handle, CREATE_SUSPENDED, &Id);
if(!Thread)
{ ShowMessage("Error! Cannot create thread.");
Application->Terminate();
}
}

void __fastcall TForm1::StartClick(TObject *)
{
ResumeThread(Thread);
Start->Enabled = false;
Stop->Enabled = true;
}

void __fastcall TForm1::StopClick(TObject *)
{ SuspendThread(Thread);
Stop->Enabled = false;
Start->Enabled = true;
}
//---------------------------------------------------------------------------
O S K R
Responder Con Cita