📄 unitsetupform.pas
字号:
unit UnitSetupForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Buttons, IniFiles;
type
TFormSetup = class(TForm)
PageControl1: TPageControl;
TabSheet2: TTabSheet;
GroupBox2: TGroupBox;
Label6: TLabel;
SMSCenter: TEdit;
TabSheet1: TTabSheet;
GroupBox1: TGroupBox;
Label1: TLabel;
Label3: TLabel;
cmbComPort: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
cmbBaudRate: TComboBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
end;
procedure WriteIniFile;
implementation
uses UnitSMS;
{$I define.inc}
{$R *.dfm}
procedure TFormSetup.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TFormSetup.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TFormSetup.FormShow(Sender: TObject);
var
i: Integer;
begin
SMSCenter.Text := g_sSMSCenter;
cmbComPort.ItemIndex := -1;
for i:=0 to cmbComPort.Items.Count-1 do
begin
if cmbComPort.Items.Strings[i] = g_sComPort then
begin
cmbComPort.ItemIndex := i;
break;
end
end;
cmbBaudRate.ItemIndex := -1;
for i:=0 to cmbBaudRate.Items.Count-1 do
begin
if cmbBaudRate.Items.Strings[i] = IntToStr(g_iBaudRate) then
begin
cmbBaudRate.ItemIndex := i;
break;
end
end;
end;
procedure TFormSetup.BitBtn1Click(Sender: TObject);
begin
if Trim(SMSCenter.Text)='' then
begin
Application.MessageBox('请输入短信中心号码!', '提示', MB_OK + MB_ICONERROR);
PageControl1.ActivePage := TabSheet2;
SMSCenter.SetFocus;
Exit;
end;
if cmbComPort.ItemIndex = -1 then
begin
Application.MessageBox('请选择串口号!', '提示', MB_OK + MB_ICONERROR);
PageControl1.ActivePage := TabSheet1;
cmbComPort.SetFocus;
Exit;
end;
if cmbBaudRate.ItemIndex = -1 then
begin
Application.MessageBox('请选择波特率!', '提示', MB_OK + MB_ICONERROR);
PageControl1.ActivePage := TabSheet1;
cmbBaudRate.SetFocus;
Exit;
end;
if (g_sSMSCenter = Trim(SMSCenter.Text))
and(g_sComPort = cmbComPort.Items.Strings[cmbComPort.ItemIndex])
and(g_iBaudRate = StrToInt(cmbBaudRate.Items.Strings[cmbBaudRate.ItemIndex])) then
begin
Application.MessageBox('配置参数未作修改!', '提示', MB_OK + MB_ICONQUESTION);
end;
g_sSMSCenter := Trim(SMSCenter.Text);
g_sComPort := cmbComPort.Items.Strings[cmbComPort.ItemIndex];
g_iBaudRate := StrToInt(cmbBaudRate.Items.Strings[cmbBaudRate.ItemIndex]);
WriteIniFile;
Application.MessageBox('修改配置参数成功,请重新启动系统生效!', '提示', MB_OK + MB_ICONWARNING);
Close;
end;
procedure WriteIniFile;
var
s: string;
IniFile: TIniFile;
begin
s := ExtractFilePath(Application.ExeName) + SYSINIFILE;
try
IniFile := Nil;
IniFile := TIniFile.Create(s);
IniFile.WriteString('SMS', 'SMSCenter', g_sSMSCenter);
IniFile.WriteString('Serial', 'ComPort', g_sComPort);
IniFile.WriteString('Serial', 'BaudRate', IntToStr(g_iBaudRate));
finally
IniFile.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -