(*--- El siguiente programa presenta el reverso de ejecutar el programa cuando usamos hilos y sin hilos.
respuesta. Al hacer clic en el botón UsedThread, se crea un hilo.
Al cambiar el tamaño del formulario y moverlo. Cuando se presiona el botón NousedThread, si no se crea el hilo, enviaremos
¡Ahora no puede hacer nada más antes de que se calcule el programa!
Unidad Unidad1;
interfaz
usos
Windows, mensajes, sysutils, variantes, clases, gráficos, controles, formularios,
Diálogo, stdctrls, botones;
tipo
TForm1 = class (tForm)
UsedThread: tbitBtn;
Nousedthread: tbitbtn;
Procedimiento usado threadClick (remitente: tobject);
procedimiento nousedThreadClick (remitente: tobject);
Privado
{Declaraciones privadas}
público
{Declaraciones públicas}
fin;
varilla
Form1: tform1;
Implementación
{$ R *.dfm}
function myThreadFunc (p: puntero): longInt; stdcall;
varilla
I: longint;
DC: HDC;
S: cadena;
Comenzar
Dc: = getDC (form1.handle);
para i: = 0 a 500000 comienza
S: = intToStr (i);
TextOut (DC, 10,10, PCHAR (S), Longitud (s));
fin;
LiberC (Form1.Handle, DC);
fin;
procedimiento tForm1.usedThreadClick (remitente: tobject);
varilla
hthread: Thandle; // Defina un mango
Threadid: dword;
Comenzar
// Crear un hilo y la función de hilo se llama al mismo tiempo
hthread: = createthread (nil, 0,@mythreadfunc, nil, 0, threadid);
Si hthread = 0 entonces
MessageBox (Handle, 'nocreatreathread', nil, mb_ok);
fin;
procedimiento tform1.nousedThreadClick (remitente: tobject);
Comenzar
MyThreadFunc (nulo);
// Cuando no se crea un hilo, la función de subproceso se llama directamente
fin;
fin.