從.INI文件中獲取字符串
var
strResult:pchar;
begin
GetPrivateProfileString(
´windows´, // []中標(biāo)題的名字
´NullPort´, // =號(hào)前的名字
´NIL´, // 如果沒有找到字符串時(shí),返回的默認(rèn)值
strResult, //存放取得字符
100, //取得字符的允許最大長度
´c:/forwin95/win.ini´ // 調(diào)用的文件名
);
edit1.text:=strResult; //顯示取得字符串
從.INI文件中獲取整數(shù)
edit1.text:=inttostr(GetPrivateProfileInt(
´intl´, // []中標(biāo)題的名字
´iCountry´, // =號(hào)前的名字
0,// 如果沒有找到整數(shù)時(shí),返回的默認(rèn)值
´c:/forwin95/win.ini´ // 調(diào)用的文件名
));
向.INI文件寫入字符串
WritePrivateProfileString(
´windows´, // []中標(biāo)題的名字
´load´, // 要寫入“=”號(hào)前的字符串
´accca´, //要寫入的數(shù)據(jù)
´c:/forwin95/win.ini´ // 調(diào)用的文件名
);
向.INI文件寫入整數(shù)
WritePrivateProfileSection(
´windows´, // []中標(biāo)題的名字
´read=100´, // 要寫入的數(shù)據(jù)
´c:/forwin95/win.ini´ // 調(diào)用的文件名
);
上面的方法是調(diào)用API函數(shù),下面介紹另一種不用API從.INI文件中獲取字符的方法
var MyIni: TIniFile;
begin
MyIni := TIniFile.Create(´WIN.INI´);//調(diào)用的文件名
edit1.text:=MyIni.ReadString(´Desktop´, ´Wallpaper´, ´´);//取得字符
end;
向.INI文件中寫入字符的方法
var MyIni: TIniFile;
begin
MyIni := TIniFile.Create(´WIN.INI´);//調(diào)用的文件名
DelphiIni.WriteString(´Desktop´, ´Wallpaper´, ´c:/a.bmp´);
end;