读取时用split 分成数组,转换一下类型就可以了
eg:
dim s as string
for i=0 to ubound(btyChrA)-1
s=s & "," & btyChrA(i)
next
s=right(s,len(s)-1)'去掉前面加上的"逗号"
保存到ini文件就行了procedure TForm1FormClose(Sender: TObject; var Action: TCloseAction);beginWith TINIFileCreate('aini') do//创建ainibeginWriteBool('MySetting', 'CheckBox1_Checked', CheckBox1Checked);{保存到MySetting下面的CheckBox1_Checked子键下,然后把Checkbox1的是否按下状态写进去}
WriteString('MySetting', 'Edit1_Text', Edit1Text);//同上end;end;procedure TForm1FormCreate(Sender: TObject);//读入aini文件中的设置beginWith TINIFileCreate('aini') do//打开已创建的ainibeginCheckBox1Checked := ReadBool('MySetting', 'CheckBox1_Checked', False);{同上面的写入一样,这里是读取ReadBool和WriteBool是两个BOOL值的写入方法}这是我常用的ini模块文件。拿去用吧。
调用:
Write_ini "设置", "串口号", "1"
Text1Text = Read_ini("设置", "串口号")
inifuncbas:
Attribute VB_Name = "IniFuncs"
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
Const inifilename = "\noteini"
Public Sub Write_ini(ByVal Appname As String, ByVal Itemname As String, ByVal Value As String)
Dim A As Long
A = WritePrivateProfileString(Appname, Itemname, Value, AppPath & inifilename)
If A = 0 Then MsgBox ("写INI文件时出错!")
End Sub
Public Function Read_ini(ByVal Appname As String, ByVal Itemname As String)
Dim A As Long
Dim T As String 255
T = Empty
A = GetPrivateProfileString(Appname, Itemname, "", T, 255, AppPath & inifilename)
If A = 0 Then
Read_ini = Empty
Else
Read_ini = Left$(T, Len(Trim$(T)) - 1)
End If
End Function
Public Sub Delete_ini_item(ByVal Appname As String, ByVal Itemname As String)
WritePrivateProfileString Appname, Itemname, 0&, AppPath & inifilename
End Sub
Public Sub Delete_ini_app(ByVal Appname As String)
WritePrivateProfileSection Appname, 0&, AppPath & inifilename
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)