что-то типа (код грязненький)
Const CfgLoader__SEP$="="
Type TOneCfgParam
Field Name$
Field Value$
End Type
Function CfgLoader_CreateParam.TOneCfgParam(Name$,Val$)
;DebugLog Name+"="+Val
Local OCP.TOneCfgParam=New TOneCfgParam
OCP\Name=Name
OCP\Value=Val
Return OCP
End Function
Function CfgLoader_GetParam.TOneCfgParam(Name$)
For OCP.TOneCfgParam=Each TOneCfgParam
If OCP\Name=Name
Return OCP
EndIf
Next
Return Null
End Function
Function CfgLoader_GetParamVal$(Name$)
Local OCP.TOneCfgParam=CfgLoader_GetParam(Name)
If OCP=Null
RuntimeError "Param "+Name+" not found!"
EndIf
Return OCP\Value
End Function
Function CfgLoader_ParseParam.TOneCfgParam(OneLine$)
Local I%=Instr(OneLine,CfgLoader__SEP,1)
Local Name$=Left(OneLine,I-1)
Local Value$=Right(OneLine,Len(OneLine)-I)
Return CfgLoader_CreateParam(Name,Value)
End Function
Function CfgLoader_LoadCfgFromFile(FileName$)
Local File%=ReadFile(FileName)
If File=False
RuntimeError "File "+FileName+" not found!"
EndIf
Local OneLine$
While Not Eof(File)
OneLine=ReadLine(File)
CfgLoader_ParseParam(OneLine)
Wend
CloseFile(File)
End Function
Сообщение от cfg.txt
WinXSize=800
WinYSize=600
|
CfgLoader_LoadCfgFromFile("cfg.txt")
Global WinXSize%=Int(CfgLoader_GetParamVal("WinXSize"))
Global WinYSize%=Int(CfgLoader_GetParamVal("WinYSize"))