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