Rubrique précédente: DeleteIniEntry : Supprimer une entrée d'un fichier d'initialisationRubrique suivante: ReadIniSection – Extraire une section


DeleteIniSection : Supprimer une section d'un fichier d'initialisation

Valide sur les plates-formes UNIX

La fonction DeleteIniSection supprime une section entière du fichier d'initialisation (.ini) spécifié.

Format de la fonction :

DeleteIniSection(section as String, filename as String) as Boolean
section

Identifie la section à supprimer.

nom_fichier

Indique le nom du fichier d'initialisation (.ini).

En cas de réussite, la fonction renvoie la valeur True. Dans le cas contraire, elle renvoie la valeur False.

Exemple :

Cet exemple lit dans le fichier c:\temp\test.ini, dans la section LIST et dans la section SINGLE l'entrée Entry, puis les affiche. L'exemple supprime la section LIST et l'entrée Entry de la section SINGLE.

Function strTok(in As string, BYREF pos As Integer, token As String, BYREF out As String) As Boolean
	Dim buf As String
	Dim len As Integer

	If (pos > Len(in)) Then
		strTok = FALSE
	Else
		buf = Mid(in, pos)
		len = Instr(buf, token)
		If len = 0 Then
			out = buf
			pos = pos + Len(buf) + 1
		Else
			out = Mid(buf, 0, len-1)

pos = pos + len + 1
		End If
		strTok = True
	End If
End Function

Dim attrList, str, lf As string
Dim pos As Integer

' Effacer l'écran
ClrScr()

If Not(ReadIniSection("LIST", attrList, "c:\temp\test.ini")) Then
	MessageBox("Impossible de lire la section LIST", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(1)
	quitter
End If
Print("[LIST]")
pos = 0
lf = chr(10)
While (strTok(attrList, pos, lf, str))
	Print(str)
Wend

If Not(ReadIniEntry("SINGLE", "Entry", attrList, "c:\temp\test.ini")) Then

MessageBox("Impossible de lire la section SINGLE", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(2)
	quitter
End If

Print("[SINGLE]" + NEWLINE$ + "Entry=" + attrList)

If Not(DeleteIniEntry("SINGLE", "Entry", "c:\temp\test.ini")) Then
	MessageBox("Impossible de supprimer l'entrée [SINGLE]", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(3)
	quitter
End If
If Not(DeleteIniSection("LIST", "c:\temp\test.ini")) Then
	MessageBox("Impossible de supprimer la section LIST", "DMS", MB_OK + MB_ICONEXCLAMATION)

SetStatus(4)
	quitter
End If