Update: I added the following code:
function TSettingsForm.AppDataPath: string; //CSIDL_APPDATA Individual user Data //CSIDL_COMMON_APPDATA Common to Computer Data // works so long as people have at least IE 4. (and Win95 or better) var r: Bool; path: array[0..Max_Path] of Char; begin r := ShGetSpecialFolderPath(0, path, CSIDL_APPDATA, False) ; if r then result := path else result := ''; end;
And I changed the setinifilename function (see below). It will not create a folder structure.
- End of update -
I'm for a while, which is what not to do. This is how I save my software settings. I just tested it on Vista, not registered as an administrator, and it gives me an error message, I can not write the ini file. So I assume that I should write data to the data folder? I have never used vista / win7 before and want this software to be compatible with Windows 2K +. What to do to save the settings. I also really did not want to mess with the registry, because every little bit that you add to it slows down the computer much more ... (or it seems)
Thanks for any input.
procedure TSettingsForm.setinifilename; var filename:string; Path:string; begin filename:='key.ini'; path:=AppDataPath+'\MyCompanyName\ProductName\'; if NOT DirectoryExists(path) then CreateDir(path); inifilename:= path+filename; end; procedure TSettingsForm.SaveSettings; var appINI: TIniFile; begin appINI := TIniFile.Create(inifilename) ; try low:= Trunc (edt_low.value); high:=Trunc (edt_high.value); appINI.WriteInteger('SPEED','LOW',low); appINI.WriteInteger('SPEED','HIGH',high); appINI.WriteString('PROXY','SERVER',edtProxyServer.Text); appINI.WriteString('PROXY','PORT',edtProxyPort.Text); appINI.WriteString('PROXY','USERNAME',edtProxyUserName.Text); appINI.WriteString('PROXY','PASSWORD',edtProxyPass.Text); // status.text:='Saved Data'; finally appIni.Free; end; end; procedure TSettingsForm.GetSettings; Var appINI : TIniFile; begin appINI := TIniFile.Create(inifilename) ; try //if no last user return an empty string edt_low.value:= appINI.ReadInteger('SPEED','LOW',0); edt_high.value:= appINI.ReadInteger('SPEED','HIGH',0); low:= Trunc (edt_low.Value); high := Trunc (edt_high.Value); edtProxyServer.Text:=appINI.ReadString('PROXY','SERVER',''); edtProxyPort.Text:=appINI.ReadString('PROXY','PORT','0'); edtProxyUserName.Text:=appINI.ReadString('PROXY','USERNAME',''); edtProxyPass.Text:= appINI.ReadString('PROXY','PASSWORD',''); finally appINI.Free; end; end;