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

📄 searchhexfrm.pas

📁 === === === MiniHex 1.61 源程序说明 ============================== “$(MiniHex)Source”目录中的所有
💻 PAS
字号:
unit SearchHexFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, HexEdit;

type
  TSearchHexData = record
    Text: string;
    AllDoc: Boolean;
    Opt: TSearchHexOptions;
  end;

  TSearchHexForm = class(TForm)
    Label1: TLabel;
    TextComboBox: TComboBox;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    UseWildCheckBox: TCheckBox;
    WildCharEdit: TEdit;
    WildCountEdit: TEdit;
    GroupBox2: TGroupBox;
    OnlyBlockCheckBox: TCheckBox;
    AllDocCheckBox: TCheckBox;
    SearchButton: TButton;
    CancelButton: TButton;
    HelpButton: TButton;
    DefaultButton: TButton;
    procedure SearchButtonClick(Sender: TObject);
    procedure CancelButtonClick(Sender: TObject);
    procedure HelpButtonClick(Sender: TObject);
    procedure DefaultButtonClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure UseWildCheckBoxClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    function CheckValid: Boolean;

  public
    { Public declarations }
    procedure GetData(var Value: TSearchHexData);

  end;

var
  SearchHexForm: TSearchHexForm;

function ShowSearchHexForm(var Value: TSearchHexData): Boolean;

implementation

uses Misc, NumBase;

{$R *.DFM}

function ShowSearchHexForm(var Value: TSearchHexData): Boolean;
begin
  Result := (SearchHexForm.ShowModal = mrOk);
  if Result then SearchHexForm.GetData(Value);
end;

procedure TSearchHexForm.GetData(var Value: TSearchHexData);
var
  WildValue: Integer;
begin
  Value.Text := TextComboBox.Text;
  Value.AllDoc := AllDocCheckBox.Checked;
  Value.Opt.OnlyBlock := OnlyBlockCheckBox.Checked;
  Value.Opt.UseWild := UseWildCheckBox.Checked;
  StrToIntAsHex(WildValue, WildCharEdit.Text);
  Value.Opt.WildChar := Chr(Cardinal(WildValue));
  Value.Opt.WildCount := StrToIntDef(WildCountEdit.Text, 1);
end;

function TSearchHexForm.CheckValid: Boolean;
begin
  Result := True;
  if TextComboBox.Text = '' then
  begin
    Result := False;
    TextComboBox.SetFocus;
    Exit;
  end;
  if not IsHexStr(TextComboBox.Text) then
  begin
    Result := False;
    MsgBox('十六进制串不正确。示范:FFAB1200DE。');
    TextComboBox.SetFocus;
    Exit;
  end;
  if Length(TextComboBox.Text) = 1 then
  begin
    TextComboBox.Text := '0' + TextComboBox.Text; 
  end;
  if not IsHexStr(WildCharEdit.Text) then
  begin
    Result := False;
    MsgBox('通配符不正确。');
    WildCharEdit.SetFocus;
    Exit;
  end;
  if not IsDecStr(WildCountEdit.Text) then
  begin
    Result := False;
    MsgBox('通配符代表字节数不正确。');
    WildCountEdit.SetFocus;
    Exit;
  end;
end;

procedure TSearchHexForm.FormCreate(Sender: TObject);
begin
  UseWildCheckBoxClick(nil);
end;

procedure TSearchHexForm.SearchButtonClick(Sender: TObject);
begin
  if CheckValid then
  begin
    TextComboBox.Items.Insert(0, TextComboBox.Text);
    ModalResult := mrOk;
  end;
end;

procedure TSearchHexForm.CancelButtonClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TSearchHexForm.HelpButtonClick(Sender: TObject);
begin
//
end;

procedure TSearchHexForm.DefaultButtonClick(Sender: TObject);
begin
  TextComboBox.Text := '';
  OnlyBlockCheckBox.Checked := False;
  AllDocCheckBox.Checked := False;
  UseWildCheckBox.Checked := False;
  WildCharEdit.Text := '3F';
  WildCountEdit.Text := '1';
end;

procedure TSearchHexForm.FormActivate(Sender: TObject);
begin
  TextComboBox.SetFocus;
end;

procedure TSearchHexForm.UseWildCheckBoxClick(Sender: TObject);
begin
  if UseWildCheckBox.Checked then
  begin
    WildCharEdit.Enabled := True;
    WildCountEdit.Enabled := True;
    WildCharEdit.Color := clWindow;
    WildCountEdit.Color := clWindow;
  end else
  begin
    WildCharEdit.Enabled := False;
    WildCountEdit.Enabled := False;
    WildCharEdit.Color := clBtnFace;
    WildCountEdit.Color := clBtnFace;
  end;
end;

end.

⌨️ 快捷键说明

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