📄 setsizefrm.pas
字号:
unit SetSizeFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Misc;
type
TSetSizeForm = class(TForm)
GroupBox1: TGroupBox;
MsgLabel: TLabel;
ValueEdit: TEdit;
OkButton: TButton;
CanclButton: TButton;
procedure OkButtonClick(Sender: TObject);
procedure CanclButtonClick(Sender: TObject);
private
{ Private declarations }
function CheckValid: Boolean;
public
{ Public declarations }
procedure SetData(Value: Integer);
procedure GetData(var Value: Integer);
end;
var
SetSizeForm: TSetSizeForm;
function ShowSetSizeForm(var Value: Integer; Caption, Msg: string): Boolean;
implementation
{$R *.DFM}
function ShowSetSizeForm(var Value: Integer; Caption, Msg: string): Boolean;
var
Frm: TSetSizeForm;
begin
Frm := TSetSizeForm.Create(Application);
Frm.SetData(Value);
Frm.Caption := Caption;
Frm.MsgLabel.Caption := Msg;
Result := (Frm.ShowModal = mrOk);
Frm.GetData(Value);
Frm.Free;
end;
function TSetSizeForm.CheckValid: Boolean;
var
Value, R: Integer;
begin
Result := True;
if not IsInt(ValueEdit.Text) then
begin
MessageBox(Handle, '输入值非法,请重新输入!', '错误', 48);
ValueEdit.SelectAll;
ValueEdit.SetFocus;
Result := False;
end else
begin
Value := StrToInt(ValueEdit.Text);
if Value <= 0 then
begin
MessageBox(Handle, '输入值必须大于0,请重新输入!', '错误', 48);
ValueEdit.SelectAll;
ValueEdit.SetFocus;
Result := False;
end
else if Value >= 32 * 1024 * 1024 then
begin
R := MessageBox(Handle, '您输入的值大于32M,如果您的电脑虚拟内存不够,将会导致内存溢出错误!' + #13 + #10 + '确定吗?', '警告', 36 + 256);
if R = ID_NO then Result := False;
end;
end;
end;
procedure TSetSizeForm.SetData(Value: Integer);
begin
ValueEdit.Text := IntToStr(Value);
end;
procedure TSetSizeForm.GetData(var Value: Integer);
begin
Value := StrToIntDef(ValueEdit.Text, 0);
end;
procedure TSetSizeForm.OkButtonClick(Sender: TObject);
begin
if not CheckValid then Exit;
ModalResult := mrOk;
end;
procedure TSetSizeForm.CanclButtonClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -