📄 fillblockfrm.pas
字号:
unit FillBlockFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TFillBlockData = record
Fixed: Boolean;
FixValue: Byte;
RndFromVal: Integer;
RndToVal: Integer;
end;
TFillBlockForm = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label3: TLabel;
FixValComboBox: TComboBox;
FixValRadioButton: TRadioButton;
RndValRadioButton: TRadioButton;
RndFromEdit: TEdit;
RndToEdit: TEdit;
RndFromUpDown: TUpDown;
RndToUpDown: TUpDown;
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 GetData(var Value: TFillBlockData);
end;
var
FillBlockForm: TFillBlockForm;
function ShowFillBlockForm(var Value: TFillBlockData): Boolean;
implementation
uses Misc;
{$R *.DFM}
function ShowFillBlockForm(var Value: TFillBlockData): Boolean;
var
Frm: TFillBlockForm;
begin
Frm := TFillBlockForm.Create(Application);
Result := (Frm.ShowModal = mrOk);
if Result then Frm.GetData(Value);
Frm.Free;
end;
function TFillBlockForm.CheckValid: Boolean;
var
I, J: Integer;
begin
if not IsInt(FixValComboBox.Text) then
begin
MsgBox('你输入的数值不正确!');
Result := False;
Exit;
end;
I := StrToInt(FixValComboBox.Text);
if (I < 0) or (I > 255) then
begin
MsgBox('固定值必须限制在0-255之间。');
FixValComboBox.SelectAll;
FixValComboBox.SetFocus;
Result := False;
Exit;
end;
I := RndFromUpDown.Position;
J := RndToUpDown.Position;
if (I > J) then
begin
MsgBox('随机值的起始值必须小于终了值。');
Result := False;
Exit;
end;
Result := True;
end;
procedure TFillBlockForm.GetData(var Value: TFillBlockData);
begin
Value.Fixed := FixValRadioButton.Checked;
Value.FixValue := StrToIntDef(FixValComboBox.Text, 0);
Value.RndFromVal := RndFromUpDown.Position;
Value.RndToVal := RndToUpDown.Position;
end;
procedure TFillBlockForm.OkButtonClick(Sender: TObject);
begin
if not CheckValid then Exit;
ModalResult := mrOk;
end;
procedure TFillBlockForm.CancelButtonClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TFillBlockForm.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 TFillBlockForm.FormCreate(Sender: TObject);
begin
FixValRadioButtonClick(Sender);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -