在Windows中利用.INI文件做程序有關(guān)數(shù)據(jù)的存儲(chǔ)工作是很常見(jiàn)的,其中涉及了讀和寫.INI文件問(wèn)題,下面就介紹幾種不同的方法給大家參考:
從.INI文件中獲取字符串
var
strResult:pchar;
begin
GetPrivateProfileString(
windows, // []中標(biāo)題的名字
NullPort, // =號(hào)前的名字
NIL, // 如果沒(méi)有找到字符串時(shí),返回的默認(rèn)值
strResult, //存放取得字符
100, //取得字符的允許長(zhǎng)度
c:\forwin95\win.ini // 調(diào)用的文件名
);
edit1.text:=strResult; //顯示取得字符串
從.INI文件中獲取整數(shù)
edit1.text:=inttostr(GetPrivateProfileInt(
intl, // []中標(biāo)題的名字
iCountry, // =號(hào)前的名字
0,// 如果沒(méi)有找到整數(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)用的文件名
);
從.INI文件中獲取字符串
var
strResult:pchar;
begin
GetPrivateProfileString(
windows, // []中標(biāo)題的名字
NullPort, // =號(hào)前的名字
NIL, // 如果沒(méi)有找到字符串時(shí),返回的默認(rèn)值
strResult, //存放取得字符
100, //取得字符的允許長(zhǎng)度
c:\forwin95\win.ini // 調(diào)用的文件名
);
edit1.text:=strResult; //顯示取得字符串
從.INI文件中獲取整數(shù)
edit1.text:=inttostr(GetPrivateProfileInt(
intl, // []中標(biāo)題的名字
iCountry, // =號(hào)前的名字
0,// 如果沒(méi)有找到整數(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)用的文件名
);

