📄 inscharfrm.pas
字号:
unit InsCharFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, Misc;
type
TInsCharData = record
Fixed: Boolean;
FixValue: Byte;
RndFromVal: Integer;
RndToVal: Integer;
Count: Integer;
end;
TInsCharForm = class(TForm)
GroupBox1: TGroupBox;
FixValComboBox: TComboBox;
FixValRadioButton: TRadioButton;
RndValRadioButton: TRadioButton;
Label1: TLabel;
Label3: TLabel;
RndFromEdit: TEdit;
RndToEdit: TEdit;
CountComboBox: TComboBox;
Label2: TLabel;
RndFromUpDown: TUpDown;
RndToUpDown: TUpDown;
Bevel1: TBevel;
OkButton: TButton;
CancelButton: TButton;
procedure OkButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
procedure FixValRadioButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function CheckValid: Boolean;
public
{ Public declarations }
procedure SetData(Value: TInsCharData);
procedure GetData(var Value: TInsCharData);
end;
var
InsCharForm: TInsCharForm;
function ShowInsCharForm(var Value: TInsCharData): Boolean;
implementation
{$R *.DFM}
function ShowInsCharForm(var Value: TInsCharData): Boolean;
var
Frm: TInsCharForm;
begin
Frm := TInsCharForm.Create(Application);
Result := (Frm.ShowModal = mrOk);
if Result then Frm.GetData(Value);
Frm.Free;
end;
function TInsCharForm.CheckValid: Boolean;
var
i, j: Integer;
begin
if not IsInt(FixValComboBox.Text) or
not IsInt(CountComboBox.Text) then
begin
MessageBox(Handle, '你输入的数值是非法数值!', '错误', 48);
Result := False;
Exit;
end;
i := StrToInt(FixValComboBox.Text);
if (i < 0) or (i > 255) then
begin
MessageBox(Handle, '固定值必须限制在0-255之间.', '错误', 48);
FixValComboBox.SelectAll;
FixValComboBox.SetFocus;
Result := False;
Exit;
end;
i := StrToInt(CountComboBox.Text);
if (i <= 0) then
begin
MessageBox(Handle, '字节数必须大于0.', '错误', 48);
CountComboBox.SelectAll;
CountComboBox.SetFocus;
Result := False;
Exit;
end;
i := RndFromUpDown.Position;
j := RndToUpDown.Position;
if (i > j) then
begin
MessageBox(Handle, '随机值的起始值必须小于终了值.', '错误', 48);
Result := False;
Exit;
end;
Result := True;
end;
procedure TInsCharForm.SetData(Value: TInsCharData);
begin
FixValRadioButton.Checked := Value.Fixed;
RndValRadioButton.Checked := not Value.Fixed;
FixValComboBox.Text := IntToStr(Value.FixValue);
RndFromUpDown.Position := Value.RndFromVal;
RndToUpDown.Position := Value.RndToVal;
CountComboBox.Text := IntToStr(Value.Count);
end;
procedure TInsCharForm.GetData(var Value: TInsCharData);
begin
Value.Fixed := FixValRadioButton.Checked;
Value.FixValue := StrToIntDef(FixValComboBox.Text, 0);
Value.RndFromVal := RndFromUpDown.Position;
Value.RndToVal := RndToUpDown.Position;
Value.Count := StrToIntDef(CountComboBox.Text, 0);
end;
procedure TInsCharForm.OkButtonClick(Sender: TObject);
begin
if CheckValid then
ModalResult := mrOk;
end;
procedure TInsCharForm.CancelButtonClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TInsCharForm.FixValRadioButtonClick(Sender: TObject);
begin
RndFromUpDown.Enabled := not FixValRadioButton.Checked;
RndToUpDown.Enabled := not FixValRadioButton.Checked;
RndFromEdit.Enabled := not FixValRadioButton.Checked;
RndToEdit.Enabled := not FixValRadioButton.Checked;
FixValComboBox.Enabled := FixValRadioButton.Checked;
end;
procedure TInsCharForm.FormCreate(Sender: TObject);
begin
FixValRadioButtonClick(Sender);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -