前のトピック: DeleteIniSection - 初期化ファイルのセクションの削除次のトピック: WriteIniEntry - .ini ファイルへの値の格納


ReadIniSection - セクションの取得

UNIX および Windows プラットフォームで有効

ReadIniSection 関数は初期化(.ini)ファイルからセクション全体を取得します。

この初期化ファイル(.ini)関数の形式は、以下のとおりです。

ReadIniSection( section as String, result as String, filename as String) as Integer
section

取得するセクションを指定します。

result

セクションを取得する文字列変数を指定します。

filename

初期化(.ini)ファイルの名前を指定します。 Windows 環境でファイル名のみを指定した場合は、Windows ディレクトリが検索されますが、Windows 以外の環境では現在のディレクトリが検索されます。

ReadIniEntry() および ReadIniSection() は、呼び出しに成功した場合、正の値を返します。失敗した場合は、ゼロ(0)を返します。 この関数は section で指定した名前と一致するセクションを初期化ファイル内で検索し、すべてのエントリを以下のフォーマットで結果ファイルにコピーします。

Entry_1 = Value_1 <LF>
Entry_n = Value_n <LF>

例: ReadIniSection 関数

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

' clear screen
ClrScr()

If Not(ReadIniSection("LIST", attrList, "c:¥temp¥test.ini")) Then
	MessageBox("Can not read LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(1)
	終了
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("Can not read SINGLE section", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(2)
	終了
End If

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

If Not(DeleteIniEntry("SINGLE", "Entry", "c:¥temp¥test.ini")) Then
	MessageBox("Can not delete [SINGLE].Entry ", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(3)
	終了
End If
If Not(DeleteIniSection("LIST", "c:¥temp¥test.ini")) Then
	MessageBox("Can not delete LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)

SetStatus(4)
	終了
End If