📄 convertset.pas
字号:
unit ConvertSet;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Mask, DFOutParaImplBody;
type
TfmCSNetConvSet = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label6: TLabel;
Label7: TLabel;
Label15: TLabel;
cbxAutoIP: TCheckBox;
cbWorkType: TComboBox;
lePort: TLabeledEdit;
leServerPort: TLabeledEdit;
cbxUseOcx: TCheckBox;
LabeledEdit1: TLabeledEdit;
TabSheet2: TTabSheet;
Label4: TLabel;
Label5: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
cbBaudRate: TComboBox;
cbDatabit: TComboBox;
cbCheckdata: TComboBox;
cbStopbit: TComboBox;
cbFlowmode: TComboBox;
leMinSendTime: TLabeledEdit;
updMinSendTime: TUpDown;
leMinSendByte: TLabeledEdit;
updMinSendByte: TUpDown;
Panel1: TPanel;
btnOK: TButton;
btnCancel: TButton;
meServerIP: TEdit;
meIPAddr: TEdit;
meMarkAddr: TEdit;
meGateway: TEdit;
meDNSAddr: TEdit;
procedure FormActivate(Sender: TObject);
procedure cbxAutoIPClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure meServerIPKeyPress(Sender: TObject; var Key: Char);
procedure meServerIPExit(Sender: TObject);
private
{ Private declarations }
FConvParam: TDF_SearchConvert;
procedure SetConvParam(const Value: TDF_SearchConvert);
function CheckIp(IP: string): boolean;
public
{ Public declarations }
property ConvParam: TDF_SearchConvert read FConvParam write SetConvParam;
end;
var
fmCSNetConvSet: TfmCSNetConvSet;
implementation
uses ConvUtils, EDC_Dlls, ParamListIntfBody, DoorForbidImplBody, unMain;
{$R *.dfm}
function TfmCSNetConvSet.CheckIp(IP: string): boolean;
var i,j:integer;
IpTemp:string;
begin
Result:=true;
if (length(IP)<7) or (length(IP)>15) then
begin
Result:=false;
exit;
end;
try
for j:=0 to 2 do
begin
i:=pos('.',ip);
if (i=0) or (i>4) then
begin
Result:=false;
exit;
end;
IpTemp:=copy(IP,1,(i-1));
IP:=copy(ip,(i+1),length(ip));
if ( (copy(IpTemp,1,1)='0') and (length(IpTemp)>1) ) or
(copy(IpTemp,1,2)='00') or
(copy(IpTemp,1,3)='000') then
begin
Result:=false;
exit;
end;
if (StrToIntDef(iptemp,-1)=-1) or (StrToIntDef(iptemp,-1)>255) then
begin
Result:=false;
exit;
end;
end;
if pos('.',ip)>0 then
Result:=false;
if ( (copy(Ip,1,1)='0') and (length(Ip)>1) ) or
(copy(Ip,1,2)='00') or
(copy(Ip,1,3)='000') then
begin
Result:=false;
exit;
end;
if (StrToIntDef(ip,-1)=-1) or (StrToIntDef(ip,-1)>255) then
begin
Result:=false;
exit;
end;
except
Result:=false;
end;
end;
procedure TfmCSNetConvSet.FormActivate(Sender: TObject);
begin
cbxAutoIPClick(cbxAutoIP);
end;
procedure TfmCSNetConvSet.cbxAutoIPClick(Sender: TObject);
begin
Label1.Enabled := not cbxAutoIP.Checked;
meIPAddr.Enabled := not cbxAutoIP.Checked;
Label2.Enabled := not cbxAutoIP.Checked;
meMarkAddr.Enabled := not cbxAutoIP.Checked;
end;
procedure TfmCSNetConvSet.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TfmCSNetConvSet.btnOKClick(Sender: TObject);
var
strMac: string;
inParam: TParamListImpl;
FSearch: TWG_DoorForbid_TCP;
convPar: TDF_SearchConvert;
i,iLen: integer;
begin
if (FConvParam <> nil) then
begin
convPar := TDF_SearchConvert.Create;
convPar.SetObjectName('DFSearchConvertObject');
convPar.FDeviceSerial := FConvParam.FDeviceSerial;
convPar.FDevicePort := FConvParam.FDevicePort;
convPar.FbStaticIP := FConvParam.FbStaticIP;
convPar.FDeviceType := FConvParam.FDeviceType;
convPar.FstrIP := FConvParam.FstrIP;
convPar.FstrIPAddr := FConvParam.FstrIPAddr;
convPar.FstrIPDns := FConvParam.FstrIPDns;
convPar.FstrIPGateway := FConvParam.FstrIPGateway;
convPar.FstrIPMask := FConvParam.FstrIPMask;
convPar.FstrMAC := FConvParam.FstrMAC;
convPar.FarComSetting[1].baudrate := FConvParam.FarComSetting[1].baudrate;
convPar.FarComSetting[1].checkmode := FConvParam.FarComSetting[1].checkmode;
convPar.FarComSetting[1].databit := FConvParam.FarComSetting[1].databit;
convPar.FarComSetting[1].flowmode := FConvParam.FarComSetting[1].flowmode;
convPar.FarComSetting[1].minsendbyte := FConvParam.FarComSetting[1].minsendbyte;
convPar.FarComSetting[1].minsendtime := FConvParam.FarComSetting[1].minsendtime;
convPar.FarComSetting[1].stopbit := FConvParam.FarComSetting[1].stopbit;
convPar.FarSockSetting[1].bUseOcx := FConvParam.FarSockSetting[1].bUseOcx;
convPar.FarSockSetting[1].iMode := FConvParam.FarSockSetting[1].iMode;
convPar.FarSockSetting[1].ipServer := FConvParam.FarSockSetting[1].ipServer;
convPar.FarSockSetting[1].port := FConvParam.FarSockSetting[1].port;
convPar.FarSockSetting[1].ServerPort := FConvParam.FarSockSetting[1].ServerPort;
for i := 2 to 8 do
begin
convPar.FarComSetting[i].baudrate := 0;
convPar.FarComSetting[i].checkmode := 0;
convPar.FarComSetting[i].databit := 0;
convPar.FarComSetting[i].flowmode := 0;
convPar.FarComSetting[i].minsendbyte := 0;
convPar.FarComSetting[i].minsendtime := 0;
convPar.FarComSetting[i].stopbit := 0;
convPar.FarSockSetting[i].bUseOcx := 0;
convPar.FarSockSetting[i].iMode := 0;
convPar.FarSockSetting[i].ipServer :=FConvParam.FarSockSetting[i].ipServer;
convPar.FarSockSetting[i].port := 0;
convPar.FarSockSetting[i].ServerPort := 0;
end;
if cbxAutoIP.Checked then
convPar.FbStaticIP := 0
else
convPar.FbStaticIP := 1;
if cbxUseOcx.Checked then
convPar.FarSockSetting[1].bUseOcx := 1
else
convPar.FarSockSetting[1].bUseOcx := 0;
iLen := Length(meIPAddr.Text);
convPar.FstrIPAddr := '';
for i := 1 to iLen do
if meIPAddr.Text[i] <> ' ' then
convPar.FstrIPAddr := convPar.FstrIPAddr+meIPAddr.Text[i];
convPar.FDevicePort := StrToIntDef(lePort.Text,60000);
iLen := Length(meMarkAddr.Text);
if convPar.FDeviceType <> 111 then
begin
convPar.FstrIPMask := '';
for i := 1 to iLen do
if meMarkAddr.Text[i] <> ' ' then
convPar.FstrIPMask := convPar.FstrIPMask+meMarkAddr.Text[i];
end;
iLen := Length(meGateway.Text);
if convPar.FDeviceType <> 111 then
begin
convPar.FstrIPGateway := '';
for i := 1 to iLen do
if meGateway.Text[i] <> ' ' then
convPar.FstrIPGateway := convPar.FstrIPGateway+meGateway.Text[i];
end;
iLen := Length(meDNSAddr.Text);
convPar.FstrIPDns := '';
for i := 1 to iLen do
if meDNSAddr.Text[i] <> ' ' then
convPar.FstrIPDns := convPar.FstrIPDns+meDNSAddr.Text[i];
convPar.FarSockSetting[1].iMode := cbWorkType.ItemIndex;
convPar.FarSockSetting[1].port := StrToInt(lePort.Text);
iLen := Length(meServerIP.Text);
for i := 1 to iLen do
if (meServerIP.Text[i] <> ' ') and (meServerIP.Text[i] <> #0) then
convPar.FarSockSetting[1].ipServer[i] := meServerIP.Text[i];
for i:=iLen+1 to 20 do
convPar.FarSockSetting[1].ipServer[i] :=#0;
convPar.FarSockSetting[1].ServerPort := StrToInt(leServerPort.Text);
convPar.FarComSetting[1].baudrate :=19200 ;//StrToInt(cbBaudRate.Text);
convPar.FarComSetting[1].databit :=8 ;//StrToInt(cbDatabit.Text);
convPar.FarComSetting[1].checkmode :=3 ;//cbCheckdata.ItemIndex;
convPar.FarComSetting[1].stopbit :=1 ;//StrToInt(cbStopbit.Text);
convPar.FarComSetting[1].flowmode := 0;//cbFlowmode.ItemIndex;
convPar.FarComSetting[1].minsendtime := 20;//updMinSendTime.Position;
convPar.FarComSetting[1].minsendbyte :=1000;// updMinSendByte.Position;
strMac := ConvParam.FstrMAC;
inParam := TParamListImpl.Create;
inParam.AddStringParam(strMac,'MacAddress');
inParam.AddObjParam(convPar);
FSearch := TWG_DoorForbid_TCP.Create;
if FSearch.SetConvertDevice(inParam) > 0 then
Self.ModalResult := mrOk
else
Self.ModalResult := mrNo;
if FSearch <> nil then
FreeAndNil(FSearch);
if inParam <> nil then
FreeAndNil(inParam);
if convPar <> nil then
FreeAndNil(convPar);
end;
end;
procedure TfmCSNetConvSet.SetConvParam(const Value: TDF_SearchConvert);
begin
FConvParam := Value;
if FConvParam <> nil then
begin
if FConvParam.FDeviceType<>111 then
begin
LabeledEdit1.Text := IntToStr(FConvParam.FDeviceSerial);
meIPAddr.Text := FConvParam.FstrIPAddr;
meMarkAddr.Text := FConvParam.FstrIPMask;
meGateway.Text := FConvParam.FstrIPGateway;
meDNSAddr.Text := FConvParam.FstrIPDns;
cbxAutoIP.Checked := (FConvParam.FbStaticIP = 0);
cbxUseOcx.Checked := (FConvParam.FarSockSetting[1].bUseOcx = 1);
cbWorkType.ItemIndex := FConvParam.FarSockSetting[1].iMode;
lePort.Text := IntToStr(FConvParam.FarSockSetting[1].port);
meServerIP.Text := FConvParam.FarSockSetting[1].ipServer;
leServerPort.Text := IntToStr(FConvParam.FarSockSetting[1].ServerPort);
cbBaudRate.ItemIndex := cbBaudRate.Items.IndexOf(IntToStr(FConvParam.FarComSetting[1].baudrate));
cbDatabit.ItemIndex := cbDatabit.Items.IndexOf(IntToStr(FConvParam.FarComSetting[1].databit));
cbCheckdata.ItemIndex := FConvParam.FarComSetting[1].checkmode;
cbStopbit.ItemIndex := cbStopbit.Items.IndexOf(IntToStr(FConvParam.FarComSetting[1].stopbit));
cbFlowmode.ItemIndex := FConvParam.FarComSetting[1].flowmode;
updMinSendTime.Position := FConvParam.FarComSetting[1].minsendtime;
updMinSendByte.Position := FConvParam.FarComSetting[1].minsendbyte;
end
else
begin
LabeledEdit1.Text := IntToStr(FConvParam.FDeviceSerial);
meIPAddr.Text := FConvParam.FstrIPAddr;
meMarkAddr.Text := FConvParam.FstrIPMask;
meGateway.Text := FConvParam.FstrIPGateway;
meDNSAddr.Text := FConvParam.FstrIPDns;
cbxAutoIP.Checked := (FConvParam.FbStaticIP = 0);
cbxUseOcx.Checked := (FConvParam.FarSockSetting[1].bUseOcx = 1);
cbWorkType.ItemIndex := FConvParam.FarSockSetting[1].iMode;
//lePort.Text := IntToStr(FConvParam.FarSockSetting[1].port);
lePort.Text := IntToStr(FConvParam.FDevicePort); //lrp070115
meServerIP.Text := FConvParam.FarSockSetting[1].ipServer;
leServerPort.Text := IntToStr(FConvParam.FarSockSetting[1].ServerPort);
end;
end;
end;
procedure TfmCSNetConvSet.meServerIPKeyPress(Sender: TObject;
var Key: Char);
begin
if not (key in ['0'..'9','.',#13,#8]) then
key:=#0;
end;
procedure TfmCSNetConvSet.meServerIPExit(Sender: TObject);
begin
if CheckIp((sender as TEdit).Text)=false then
begin
Showmessage( 'IP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -