5,388
社区成员
发帖
与我相关
我的任务
分享
//将一些报文保存到文本文件中,便于调试时使用***********************************
procedure Tw_zjm.writefile_pro(name, content: string);
var
fl:TextFile;
k:integer;
begin
if not fileexists(name) then
begin
k:=filecreate(name);
if k>0 then
begin
fileclose(k);
assignfile(fl,name);
append(fl);
writeln(fl,datetimetostr(now)+':');
writeln(fl,content);
closefile(fl);
end;
end
else
begin
assignfile(fl,name);
append(fl);
writeln(fl,datetimetostr(now)+':');
writeln(fl,content);
closefile(fl);
end;
end;
//****************************************************************************
procedure TForm1.Button3Click(Sender: TObject);
var
fl:TextFile;
path,s:string;
str:string;
i,j,m,n:Integer;
b:Boolean;
begin
path:=ExtractFilePath(Application.ExeName);
AssignFile(fl,path+'text.txt');
Reset(fl);
//逐行读文本文件,************************************************************
repeat
Readln(fl,str);//读取文本文件当前行内容,开始是第一行,然后逐行读取
i:=Pos('XX-ClientMac:',str);//子串在字符串中的位置,大于0说明找到子串,否则无匹配的子串
if i>0 then//有匹配的子串
begin
s:=Copy(str,i+length('XX-ClientMac:'),Length(str)-i-length('XX-ClientMac:')+1);//读取字符串中子串后的内容,就是你要的IP地址
end
else//没有匹配的子串
begin
i:=Pos('XX-ServerMac:',str);//另一子串在字符串中的位置,大于0说明找到子串,否则无匹配的子串
if i>0 then
begin
s:=Copy(str,i+length('XX-ServerMac:'),Length(str)-i-length('XX-ServerMac:')+1);//读取字符串中子串后的内容,就是你要的IP地址
end
end;
until
SeekEof(fl);//文本文件读取完成(英文解释:Returns the end-of-file status of a file, ignoring whitespace.)
CloseFile(fl);
//self.MaskEdit1.EditMask
end;