【例子介绍】生成验证码。
【相关图片】
【源码结构】function GetVerificationCode(ACanvas: TCanvas): string;
var
  i, LIndex, LLeft: Integer;
  LPoint: TPoint;
begin
  Result := '';
  for i := 1 to 4 do
  begin
    Randomize;
    LIndex := Random(36);
    Result := Result   Trim(C_Arr_Chars[LIndex])
  end;
  LLeft := 10;
  for i := 1 to Length(Result) do
  begin
    ACanvas.Font.Size := Random(10)   9;
    ACanvas.Font.Color := RGB(Random(256) and $C0, Random(256) and $C0, Random(256) and $C0);
    if Random(2) = 1 then
      ACanvas.Font.Style := [fsBold]
    else
      ACanvas.Font.Style := [fsItalic];
    begin
      ACanvas.Font.Name := Screen.Fonts[10];
      LPoint.X := Random(4)   LLeft;
      LPoint.Y := Random(5);
      ACanvas.Brush.Style := bsClear;
      ACanvas.TextOut(LPoint.X, LPoint.Y, Result[i]);
      LLeft := LPoint.X   ACanvas.TextWidth(Result[i]);
    end;
  end;
end;

 
  
					
				
评论