⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uasciiconstructorform.pas

📁 Delphi函数工厂。。。。。。。。。。。。。
💻 PAS
字号:
unit uAsciiConstructorForm;
//{$I directives.inc}
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uCustomModuleForm, ComCtrls, StdCtrls, ExtCtrls, Mask;

type
  TAsciiDialog = class;
  TAsciiConstructorForm = class(TCustomModuleForm)
    TabControl1: TTabControl;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    lblShow: TLabel;
    edtInput: TEdit;
    procedure FormPaint(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure edtInputKeyPress(Sender: TObject; var Key: Char);
    procedure edtInputChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);

  private
                            { Private declarations }
    FAsciiDialog: TAsciiDialog;
    procedure DrawGrid;
  public
                            { Public declarations }
  end;
                         { ========================== }
                        { TAsciiDialog 声明部分 }
                        { ========================== }
  TAsciiDialog = class(TCustomModuleDialog)
  private
    FModuleForm: TAsciiConstructorForm;
    FPageIndex: Integer;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function Execute: Boolean; override;

  published
    property PageIndex: Integer read FPageIndex write FPageIndex
      default 0;
  end;

var
  AsciiConstructorForm: TAsciiConstructorForm;

implementation


{$R *.dfm}
resourcestring
  SDefultMessageBoxDialogTitle = 'ASCII码快速查询';

{ TMessageBoxDialog }
constructor TAsciiDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FModuleForm := TAsciiConstructorForm.Create(Self);
  FModuleForm.FAsciiDialog := Self;
  FModuleForm.FDialogModule := Self;
  FModuleForm.Caption := SDefultMessageBoxDialogTitle;

  FWindowForm := FModuleForm;
  FPageIndex := 0;
end;

destructor TAsciiDialog.Destroy;
begin
  if FModuleForm.Visible then FModuleForm.Close;
  FModuleForm.Free;
  inherited Destroy;
end;

function TAsciiDialog.Execute: Boolean;
begin
  inherited Execute;
  Result := FModuleForm.ShowModal = mrOK;
end;

function GetAscii(const X: integer): string;
const
  specialtiesAsciiStr: array[0..31] of string = ('NUL',
    'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB',
    'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3',
    'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS',
    'GS', 'RS', 'US');
begin
//result:=' ';
  if X < 32 then
    result := specialtiesAsciiStr[X]
  else
    result := chr(X);
end;

procedure TAsciiConstructorForm.DrawGrid;
var I, J, X, Y: Integer;
  HorizMult, VertMult: integer;
  Start: integer;
begin
  inherited;
  HorizMult := (TabControl1.ClientWidth) div 8;
  VertMult := (TabControl1.ClientHeight - GroupBox1.Height - 30) div 16;
  with TabControl1.Canvas do // TabControl1
  begin
    Brush.Style := bsSolid;
    Brush.Color := clBtnFace;
    FillRect(Rect(0, 32, 530, 380));
    Pen.Width := 1;
    Pen.Style := psSolid;
    Pen.Color := clBtnHighlight;
    for I := 0 to 7 do
      for J := 0 to 15 do
        PolyLine([Point(I * HorizMult, (J + 1) * VertMult + 24),
          Point(I * HorizMult, J * VertMult + 25),
            Point((I + 1) * HorizMult - 1, J * VertMult + 25)]);
    Pen.Color := clBtnShadow;
    for I := 0 to 7 do
      for J := 0 to 15 do
        PolyLine([Point((I + 1) * HorizMult - 1, J * VertMult + 25),
          Point((I + 1) * HorizMult - 1, (J + 1) * VertMult + 24),
            Point(I * HorizMult - 1, (J + 1) * VertMult + 24)]);
    Start := TabControl1.TabIndex * 128;
    for I := 0 to 127 do
    begin
      X := I div 16;
      Y := I mod 16;
      Brush.Style := bsclear;
      font.Color := clBlack;
      TextOut(X * HorizMult + 40, Y * VertMult + 32, GetAscii(Start + I));
      font.Color := clGray;
      TextOut(X * HorizMult + 10, Y * VertMult + 32, inttostr(Start + I));
    end;
  end;
end;

procedure TAsciiConstructorForm.FormPaint(Sender: TObject);
begin
  inherited;
  DrawGrid;
end;

procedure TAsciiConstructorForm.TabControl1Change(Sender: TObject);
begin
  inherited;
  DrawGrid;
end;



procedure TAsciiConstructorForm.edtInputKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
  case Key of
    '0'..'9', #8:
  else
    Key := #0;
    Beep;
  end;
end;

procedure TAsciiConstructorForm.edtInputChange(Sender: TObject);
var value: integer;
begin
  inherited;
  /////////////////////
  //  将下面的一句放入
  //  try..except块中,
  //  避免出现错误数值
  //  提示(特别是在用户
  //  清空edtInput.text
  //  中的字符的时候)
  /////////////////////
  try
    value := strtoint(edtInput.text);
  except
    lblShow.Caption := '';
    Exit;
  end;
  if value > 127 then
    TabControl1.TabIndex := 1
  else
    TabControl1.TabIndex := 0;
  DrawGrid;
  with lblShow.Canvas do
  begin
      Brush.Style := bsSolid;
    Brush.Color := clBtnFace;
  FillRect(lblShow.Canvas.ClipRect);
  Font.Size := 12;
  Font.Color := clred;
  TextOut(1, 1, GetAscii(value));
  end;
end;

procedure TAsciiConstructorForm.FormActivate(Sender: TObject);
begin
  inherited;
TabControl1.TabIndex:=0;//如果没此句,XP下画不出ASCII码表格
end;
{$IFDEF DEBUGMODE}
initialization
  with TAsciiDialog.Create(nil) do
  begin
    Execute;
    Free;
  end;
{$ENDIF}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -