Source code:
-------------------------------------------------------------------------
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;
Type
TForm1 = class (TForm)
Edit1: TEdit;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Procedure FormShow (Sender: TObject );
Procedure Button1Click (Sender: TObject );
Procedure Button2Click (Sender: TObject );
Procedure Edit1KeyPress (Sender: TObject; var Key: Char );
*******
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
JS: integer;
Keysum: integer;
Flage: Boolean;
Hthread1: thandle;
Function rndsum (): integer; stdcall;
Implementation
{$ R *. DFM}
// {$ Apptype console}
Function rndsum (): integer; stdcall;
VaR
I: integer;
Sum1: integer;
Str1: string;
Str2: string;
Begin
Sum1: = 14;
While true do
Begin
If flage then
Begin
Flage: = false;
Randomize;
Str1: = '';
Str2: = '';
For I: = 0 to sum1-1 do
Begin
Str1: = CHR (48 + random (10 ));
Str2: = str2 + str1;
End;
Form1.label1. Caption: = str2;
End
Else
Begin
Sleep (10 );
End;
End;
End;
Procedure tform1.button1click (Sender: tobject );
VaR
ID: DWORD;
Begin
// Generate a random number thread
Flage: = true;
Hthread1: = createthread (nil, 0, @ rndsum, nil, 0, ID );
If (hthread1 = 0) then
Begin
Showmessage ('thread creation failed! ');
Exit;
End;
// Position the cursor
Form1.edit1. setfocus;
End;
Procedure tform1.button2click (Sender: tobject );
VaR
I: integer;
Begin
Halt;
End;
Procedure tform1.edit1keypress (Sender: tobject; var key: Char );
VaR
C1: string;
Oldstr: string;
Begin
// Only numbers can be entered
If not (key in ['0'... '9', #8]) then
Begin
Key: = #0;
Exit;
End;
C1: = form1.Label1. Caption;
Inc (js );
If (midstr (c1, js, 1) <> key) then // incorrect
Begin
Dec (js );
Beep;
Key: = #0;
Exit;
End;
Inc (keysum );
If (js> = 14) then
Begin
Js: = 0;
Form1.Edit1. Text: = '';
Key: = #0;
Flage: = true;
Sleep (1 );
End;
Form1.Label2. Caption: = 'number of times: '+ inttostr (keysum );
End;
Procedure TForm1.FormShow (Sender: TObject );
Begin
// Initialize the variable
Js: = 0;
Keysum: = 0;
Flage: = false;
Form1.Label1. Font. Name: = 'arial black ';
Form1.Label1. Font. Height: = 52;
Form1.Edit1. Font. Name: = 'arial black ';
Form1.Edit1. Font. Height: = 52;
End;
End.
-------------------------------------------------
Interface code:
Object Form1: TForm1
Left = 0
Top = 0
BorderIcons = [biSystemMenu, biMinimize]
Caption = #23567 #38190 #30424 #32451 #20064 ''#29482 #24735 #33021
ClientHeight = 1, 252
ClientWidth = 390
Color = clBtnFace
Font. Charset = DEFAULT_CHARSET
Font. Color = clwindowtext
Font. Height =-11
Font. Name = 'tahoma'
Font. Style = []
Oldcreateorder = false
Onshow = formshow
Pixelsperinch = 96
Textheight = 13
Object label2: tlabel
Left = 24
Top = 8
Width = 3
Height = 13
End
Object label1: tlabel
Left = 24
Top = 49
Width = 8
Height = 29
Font. charset = default_charset
Font. Color = clred
Font. Height =-24
Font. Name = 'tahoma'
Font. Style = []
ParentFont = False
End
Object Edit1: TEdit
Left = 24
Maximum = 120
Width = 353
Height = 41
Font. Charset = DEFAULT_CHARSET
Font. Color = clBlue
Font. Height =-19
Font. Name = 'tahoma'
Font. Style = []
ParentFont = False
TabOrder = 0
OnKeyPress = Edit1KeyPress
End
Object Button1: TButton
Left = 1, 208
Maximum = 203
Width = 81
Height = 30
Caption = #24320 #22987
TabOrder = 1
OnClick = Button1Click
End
Object Button2: TButton
Left = 1, 295
Maximum = 203
Width = 82
Height = 30
Caption = #36864 #20986
TabOrder = 2
OnClick = Button2Click
End
End
Source code download: http://www.rayfile.com/files/03ca62e3-14ff-11df-b22f-0015c55db73d/