有深度问题(高手请进)(50分)

  • 主题发起人 主题发起人 可爱宝宝
  • 开始时间 开始时间

可爱宝宝

Unregistered / Unconfirmed
GUEST, unregistred user!
程序的配置怎么从文本文件读入?
附一段配置


[Global]
ListenIP=3,14,172.19.100.168
ListenPort=2101
MobileConvert=2:13:86,2:5:86,2:8:86,2:16:86
//有效期
//DefaultValidityPeriod=8,+,1:0:0:0
DefaultValidityPeriod=NULL
ASP_SUPER_PASWORD=37e6d8
UniqueId_MsgId=ISCA
//have control start link timer;
SleepTimer=1000
OptionTag=0000
//0:SMPP;1:CIMD;
ProtocolFlag=0
//0:first bill code last addr; 1:first addr last bill code;
//0:4100-1100-1681100; 1:4100-1684100-1100
BillCodeAddressConvert=1

[Segment]
SegmentNumber=9
Segment1=13500000000,13599999999,111,0
Segment2=13600000000,13699999999,222,0
Segment3=13700000000,13799999999,333,0
Segment4=13800000000,13899999999,444,0
Segment5=13900000000,13999999999,555,0
Segment6=13000000000,13099999999,666,0
Segment7=13100000000,13199999999,777,0
Segment8=13200000000,13299999999,888,0
Segment9=13300000000,13399999999,999,0

[ServiceCode]
//!:非完全匹配;
//%:Smp协议发送;
CodeFrom=!PHB D,+XXTQ,168
CodeTo=%CPHB D,%TQ,169
SendUdpSmp=172.19.100.168,7912

[SMC]
//0:two link and the same user/pwd; 1:two link and different user/pwd;
GatewayMode=0
GatewayNumber=1
//control send is void
SendLinkNumber=1
Gateway1=3,14,172.19.100.168,2000,168,168,168,52,1
Gateway2=3,14,172.19.100.168,2201,DL802,P802,AGENT,52,2

GatewayNumberRX=1
GatewayNumberTX=1
Gateway1RX=3,14,172.19.100.168,2000,168,168,168,52,1
Gateway1TX=3,14,172.19.100.168,2000,168,168,168,52,1
Gateway2RX=3,14,172.19.100.168,2201,DL802,P802,AGENT,52,2
Gateway2TX=3,14,172.19.100.168,2201,DL802,P802,AGENT,52,2

TEST_SER_ALIVE=on
//1:1-trust 0-no trust;2:rsp_time;3:1-num msg rsp throw away;4:free busy;
//control send is void
TrustSend=0,300,2,1
RepeatNum=1
//0xFF-unchange
Priority=1
//0xFF-unchange
StatusReport=0
//0xFF-unchange; only use in smp;
SmpDcsCode=255
//send dest address len;
SendSmcAddressLen=11
//0:不动,1:替换,2:追加; ton; npi; 原地址;处理地址长度限制
OutSurceAddress=1,1,1,86168,11
//0:不动,1:追加; ton; npi; 86;
OutDestAddress=1,1,1,86
0:不动,1:尾部去掉,2:去86后留3位; 处理地址长度限制
InDestAddress=2,3,14
UnChangeAddr=166,169

//*转换
AddAddressNum=3
AddAddress1=31:4100,4101
AddAddress2=41:4104
AddAddress3=51:4109,4171

//转换FreeFee mobile
SendUdpSmp=0,172.19.100.168,7912
FreeMobileNumber=13971640801,13971272512,13971166457
TypeAddress=1860
TypeCode=0000

SendOutControl=0
LinkSmcClassNum=2
LinkSmcClass1=1:1,2,3,4,5
LinkSmcClass2=2:6,7,8,9

[CIMD]
UDPSMCIPAddr=172.19.100.168,2001

[ReportConfig]
//处理状态报告
StatusReportFlag=1
StatusReportAddressNum=2
//ip地址,ip端口号,权限(0:有效,255:无效)
StatusReportAddress1=172.19.100.168,2101,0
StatusReportAddress2=172.19.100.168,2101,0
EsmSriTag=32,4

[IED]
TEST_CLI_ALIVE=on
TCPIPTestFlag=0
ReadConfig=1
IedClientNum=4
//255:不下发,管理接入
IedClient1=000,BOSS,BOSS,MANAGE,52,255
IedClient2=901,ISPC901,P901,ISPC,52,0
IedClient3=902,ISPC902,P902,ISPC,52,0
IedClient4=903,DL802,P802,AGENT,52,0

[SMP]
UDPLocalSmcPort=2102
UDPLocalSmePort=2103
RemoteSendFromSmc=0
UDPRemoteIPAddr=172.19.100.168,2001

[Timer]
SEND_MSG_SER=10
SEND_MSG_CLI=13
PROCESS_SMPUDP=13
TRANS_CIMD=13
TRANS_SMGP=13
ALIVE_SER=15000
ALIVE_CLI=15000
RELINK_TIME=1000
RELINK_FLAG=on
SET_STATUS_TIME=1000

[BillCodeConver]
BillCodeNum=4
//业务类型:资费类型:资费代码-业务类型,业务类型......
BillCode1=4100:1:20-4100,4101,4102,4103
BillCode2=4200:1:20-4200,4201
BillCode3=4104:1:20-4300,4301,1010,4303
BillCode4=4999:1:20-4999
OtherCode=5000:1:20

[TraceTimeMobile]
MobileNumber=13971640801,13501370969
LinkAlertMobile=13791640801,13501370969
AlertEveryCount=10
BillCode=1010

[RemoteTrace]
ReTraceFlag=off
ReTraceRemoteIP=168.160.234.93,7310
ReTraceLocalIP=168.160.234.97,7910
ReTraceLocalName=InterFace

[Debug]
TestTag=TEST,XXPT
ReStart=off
ViewApplication=on
TraceApplication=on
DumpMessage=on
TraceTimeSpan=on
LogDirectory=C:/log
SaveLogTime=3
FileNameNum=9999
FileLineNum=10000
 
ini文件呀,这么简单。
给你个例子:
uses Inifiles;

procedure TConfigForm.OpenIni;
begin

ini:=Tinifile.create(AppDir + 'Simulator.ini');
if not fileexists('Simulator.ini')
then
begin
MoxaCfg.BaudRate := ord(B38400);
MoxaCfg.Parity := ord(P_NONE);
MoxaCfg.ByteSize := ord(BIT_8);
MoxaCfg.StopBits := ord(STOP_1);
MoxaCfg.Hw := false;
MoxaCfg.Sw := false;
MoxaCfg.Dtr := true;
MoxaCfg.Rts := true;

ini.WriteBool('window','ShowConfig',true);
ini.WriteInteger('radio','radius',5);
ini.WriteInteger('radio','NumType',1);
with MoxaCfg do
begin
ini.writeInteger('com','BaudRate',BaudRate);
ini.writeInteger('com','Parity',Parity);
ini.writeInteger('com','ByteSize',ByteSize);
ini.writeInteger('com','StopBits',StopBits);
ini.WriteBool('com','RTS/CTS',Hw);
ini.WriteBool('com','XON/XOFF',Sw);
ini.WriteBool('com','DTR',Dtr);
ini.WriteBool('com','RTS',Rts);
end;
ini.WriteInteger('map','Width',speAreaX.Value);
ini.WriteInteger('map','Height',speAreaY.Value);
ini.WriteInteger('map','Speed',speSpeed.Value);

end
else
begin
cbShow.Checked := ini.ReadBool('window','ShowConfig',true);
speRadius.Value := ini.ReadInteger('radio','radius',5);
rgRadioNum.ItemIndex := ini.ReadInteger('radio','NumType',1);
Diameter := round((speRadius.Value*2/speAreaY.Value) * MainForm.sbxBkGrd.Height);

MoxaCfg.BaudRate := ini.ReadInteger('com','BaudRate',ord(B38400));
MoxaCfg.Parity := ini.ReadInteger('com','Parity',ord(P_NONE));
MoxaCfg.ByteSize := ini.ReadInteger('com','ByteSize',ord(BIT_8));
MoxaCfg.StopBits := ini.ReadInteger('com','StopBits',ord(STOP_1));
MoxaCfg.Hw := ini.ReadBool('com','RTS/CTS',false);
MoxaCfg.Sw := ini.ReadBool('com','XON/XOFF',false);
MoxaCfg.Dtr := ini.ReadBool('com','DTR',true);
MoxaCfg.Rts := ini.ReadBool('com','RTS',true);

speAreaX.Value := ini.ReadInteger('map','Width',speAreaX.Value);
speAreaY.Value := ini.ReadInteger('map','Height',speAreaY.Value);
speSpeed.Value := ini.ReadInteger('map','Speed',speSpeed.Value);
end;
ini.Free;

end;

procedure TConfigForm.SaveIni;
begin

ini := Tinifile.create(AppDir + 'Simulator.ini');

ini.WriteBool('window','ShowConfig',cbShow.Checked);
ini.writeInteger('radio','radius',speRadius.Value);
ini.WriteInteger('radio','NumType',rgRadioNum.ItemIndex);
ini.writeInteger('com','BaudRate',MoxaCfg.Baudrate);
ini.writeInteger('com','Parity',MoxaCfg.Parity);
ini.writeInteger('com','ByteSize',MoxaCfg.ByteSize);
ini.writeInteger('com','StopBits',MoxaCfg.StopBits);
ini.WriteBool('com','RTS/CTS',MoxaCfg.Hw);
ini.WriteBool('com','XON/XOFF',MoxaCfg.Sw);
ini.WriteBool('com','DTR',MoxaCfg.Dtr);
ini.WriteBool('com','RTS',MoxaCfg.Rts);
ini.WriteInteger('map','Width',speAreaX.Value);
ini.WriteInteger('map','Height',speAreaY.Value);
ini.WriteInteger('map','Speed',speSpeed.Value);

ini.Free;

end;
 
可系统怎么读取他呀
能说详细点么?
 
可以看tinifile的源代码,只是封装了字符串的处理
 
还不够详细呀,比如说有一个ini文件是这样的:
[Options]
currX=25
currY=60
Caption="哈哈"

然后这样读取:
appPath:= ExtractFilePath(Application.ExeName)+'myalert.ini';
if(FileExists(appPath)=false) then
begin
Application.MessageBox('配置文件(myalert.ini)未找到或已被损坏!'#13#10'请重新建立...', '严重错误', MB_OK+MB_ICONERROR);
Application.Terminate;
end;
MyIniFile := TIniFile.Create(appPath);
with MyIniFile do
begin
myX:= ReadInteger('Options', 'currX', 10);
myY:= ReadInteger('Options', 'currY', 10);
myCaption:= ReadString('Options', 'Caption', 'hehe');
end;
MyIniFile.Free;
 
后退
顶部