Home > Back-end >  Random letters and Numbers, drawing on the image control, according to the code. Please solve
Random letters and Numbers, drawing on the image control, according to the code. Please solve

Time:10-14

A program, landing interface with the image display verification code, verification code generated by the function and map, under some system to display the code

Don't know is a cause or a reason code system, give advice or comments
 procedure GetRandomCheckCode (var img: Timage; Var codeStr: string); 
Const
ConstStr='0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz';
Var
I, J, K: Integer;
VPoint: TPoint;
VLeft: Integer;
X, Y: Integer;
VChaos: Integer;
The begin
CodeStr:=';

For J:=1 to 4 do
The begin
Randomize.
0.1 K:=StrToInt (Format (' % d ', [the Random (Length (constStr)))));
CodeStr:=codeStr + Trim (constStr [K]);
end;
If (Length (codeStr)=3) then
The begin
Randomize.
0.1 K:=StrToInt (Format (' % d ', [the Random (Length (constStr)))));
CodeStr:=codeStr + Trim (constStr [K]);
end;

VLeft:=5;
Img. Picture:=nil;
{set the background color}
Img. Canvas. Brush. Color:=$FEEEE2;//clAqua;
Img. Canvas. FillRect (the Rect (0, 0, img Width, img, Height));

For I:=1 to Length (codeStr) do
The begin
With img do
The begin
VChaos:=100;
For J:=0 to vChaos do
The begin
X:=the Random (img. Width);
Y:=the Random (img. Height);
Img. Canvas. Pen. Color:=clOlive;
Img. Canvas. Pen. Style:=psDot;
Img. Canvas. Pixels (X, Y) :=RGB ($C0, $C0, $C0); {noise color}
end;

Canvas, the Font Size:=the Random (10) + 11;
Canvas. The Font. Color:=RGB (Random (256) and $C0, Random (256) and $C0,
Random (256) and $C0);
Canvas, the Font Style:=[fsBold];

Canvas. The Font. The Name:=Screen Fonts [11].
VPoint. X:=the Random (4) + vLeft;
VPoint. Y:=the Random (5);
Canvas. TextOut (vPoint. X, vPoint. Y, codeStr [I]);
VLeft:=vPoint. X + Canvas. TextWidth (codeStr [I]);
end;
end;
end;

CodePudding user response:

0.1 K:=StrToInt (Format (' % d ', [the Random (Length (constStr)))));
This is a little problem! Is may return zero values, then constStr [K]. Can be a problem

CodePudding user response:

CNPACK in this one for reference
  • Related