Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Esempio Thread - ex Thread.pas

ex Thread.pas

Caricato da: Phi
Scarica il programma completo

  1. program Esempio;
  2.  
  3. uses crt, dos, windows;
  4.  
  5. type
  6. time=record
  7.  h,min,sec,s100 : word;
  8. end;
  9.  
  10. var
  11. T : time;
  12. x, y : byte;
  13. MessageThread1,MessageThread2 : Handle;
  14. MessageID1,MessageID2 : DWord;
  15. oraattivo, lampeggioattivo, scrivendo :boolean;
  16. ris1, ris2 : word;
  17.  
  18. function orologio(p:pointer):Dword;stdcall;
  19. begin
  20. sleep(1);
  21. oraattivo := true;
  22. repeat
  23.  repeat sleep(1) until not(scrivendo);
  24.  x := wherex;
  25.  y := wherey;
  26.  gotoxy(69,1);
  27.  textcolor(15);
  28.  textbackground(0);
  29.  write(space(13));
  30.  gotoxy(69,1);
  31.  with t do begin
  32.   gettime(h,min,sec,s100);
  33.   write(h,':',min,':',sec,',',s100);
  34.  end;
  35.  gotoxy(x,y);
  36.  sleep(2);
  37. until not(oraattivo);
  38. orologio:=0;
  39. end;
  40.  
  41. function lampeggio(p:pointer):Dword;stdcall;
  42. begin
  43. sleep(1);
  44. lampeggioattivo:=true;
  45. repeat
  46.  repeat sleep(1) until not(scrivendo);
  47.  scrivendo:=true;
  48.  sleep(1);
  49.  x := wherex;
  50.  y := wherey;
  51.  textcolor(10);
  52.  gotoxy(10,3);
  53.  write('Esempio');
  54.  gotoxy(x,y);
  55.  scrivendo:=false;
  56.  sleep(500);
  57.  
  58.  repeat sleep(1) until not(scrivendo);
  59.  scrivendo:=true;
  60.  sleep(1);
  61.  x := wherex;
  62.  y := wherey;
  63.  textcolor(14);
  64.  gotoxy(10,3);
  65.  write('Esempio');
  66.  gotoxy(x,y);
  67.  scrivendo:=false;
  68.  sleep(500);
  69. until not(lampeggioattivo);
  70. lampeggio:=0;
  71. end;
  72.  
  73.  
  74. BEGIN
  75. clrscr;
  76. gotoxy(1,5);
  77. MessageThread1:=CreateThread(nil,0,@orologio,nil,0,MessageID1);
  78. repeat
  79.  GetExitCodeThread(MessageThread1,@ris1);
  80. until oraattivo or (ris1<>STILL_ACTIVE);
  81. MessageThread2:=CreateThread(nil,0,@lampeggio,nil,0,MessageID2);
  82. repeat
  83.  GetExitCodeThread(MessageThread2,@ris2);
  84. until lampeggioattivo or (ris2<>STILL_ACTIVE);
  85. readln;
  86. scrivendo:=true;
  87. sleep(5);
  88. gotoxy(2,5);
  89. textcolor(15);
  90. writeln('schiaccia un tasto');
  91. scrivendo:=false;
  92. repeat delay(1) until keypressed;
  93. END.