Confix
Übersicht

![]() |
BlacksideBetreff: Confix |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo,
Ich habe einen Code geschrieben um Variablen aus einer Config zu laden, Variablen daraus zu ändern und neue Variablen hineinzuschreiben. (Ich hoffe das ist für das Codearchiv würdig ![]() Vielleicht braucht es ja irgendwer ![]() einmal die Lib: Code: [AUSKLAPPEN] Type CfgCommand
Field cmd$ Field var$ End Type Function InitCfg(cfgfile$) Local stream = ReadFile(cfgfile) Local rl$,name$,var$,curl Repeat rl = Lower$(Trim$(ReadLine(stream))) If rl <> "" Then Repeat curl=curl+1 If Mid(rl,curl,1) = "=" Then name = Trim(Mid(rl,1,curl-1)) var = Trim(Mid(rl,curl+1,(Len(rl)-curl))) CreateCfgCommand(name,var) curl = 0 Exit End If If curl > Len(rl) Then Exit Forever End If Until Eof(stream) CloseFile stream End Function Function CreateCfgCommand(cmd$,var$) Local cfg.CfgCommand = New CfgCommand cfg\cmd = cmd cfg\var = var End Function Function ReadCfgCommand$(cmd$) Local cfg.CfgCommand For cfg = Each CfgCommand If cfg\cmd = cmd Then Return cfg\var End If Next Return 0 End Function Function WriteCfg(cfgfile$) Local stream = WriteFile(cfgfile$) Local cfg.CfgCommand For cfg = Each CfgCommand WriteLine stream,cfg\cmd+" = "+cfg\var Next CloseFile stream End Function Function WriteCfgCommand(cmd$,var$) Local cfg.CfgCommand For cfg = Each CfgCommand If cfg\cmd = cmd Then cfg\var = var End If Next End Function Hier ein Beispiel: Code: [AUSKLAPPEN] Include "confix.bb"
Local milli# = MilliSecs() InitCfg("config.cfg") ;<--- Lädt die Config Local scrw = ReadCfgCommand("scrw") ;<--- Liest die angegebene Variable aus der Config Local scrh = ReadCfgCommand("scrh") Local scrt = ReadCfgCommand("scrt") Local scrm = ReadCfgCommand("scrm") Local hallo$ = ReadCfgCommand("hallo") CreateCfgCommand("test",35) ;<--- Erstellt einen neue Variable Graphics scrw,scrh,scrt,scrm Print "Reading Done..." scrw = 800 scrh = 600 Print "Changing Vars..." WriteCfgCommand("scrw",scrw) ;<-- Ändert die Angegebene Variable WriteCfgCommand("scrh",scrh) Print "Writing Config..." WriteCfg("config.cfg") ;<--- Speichert alle Änderrungen in Die Config Print "Succes..." Print "In Var: hallo -> "+hallo Print "Milliseconds: "+(MilliSecs()-milli) WaitKey und noch die zugehörige "config.cfg" zum Beispiel: Code: [AUSKLAPPEN] scrw = 640
scrh = 480 scrt = 32 scrm = 2 hallo = hallo welt! Einfach alles in einen Ordner speichern, und das Beispiel ausführen ![]() MFG Blackside |
||
Hier sollte eigentlich eine Signatur stehen! |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group