從.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檔案中取得字元的方法
varMyIni:TIniFile;
begin
MyIni:=TIniFile.Create(´WIN.INI´);//呼叫的檔案名
edit1.text:=MyIni.ReadString(´Desktop´,´Wallpaper´,´´);//取得字符
end;
向.INI檔案中寫入字元的方法
varMyIni:TIniFile;
begin
MyIni:=TIniFile.Create(´WIN.INI´);//呼叫的檔案名
DelphiIni.WriteString(´Desktop´,´Wallpaper´,´c:/a.bmp´);
end;