Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Wednesday, 31 January 2018

Project setting for absolute paths

I've noticed that with the current version of Delphi (Berlin) the project file (.dpr) uses relative paths and when you manually change the paths to absolute paths and then add a something to the project (e.g. a .pas file) it converts them back to relative paths.

I prefer to use relative paths, however the problem I have is that both the MD and the Development Manager at the company insist on using absolute paths, the MD seems to think and apparently has heard that using relative paths can causes problems. I cannot find any project or environmental setting to force the paths for the project files in the .dpr file to be absolute. Does anyone know of such a setting or why relative paths in the .dpr file cause problems? 

Thursday, 11 June 2015

TMemIniFile Vs TIniFile

Ini files have been around for some time now and are very useful for storing small amounts of data, and I use them as an alternative to the registry. Years ago I found that they had been designed with a limit of 64k, however these days it is possible to store more than that. Recently I needed to store a fair bit more than ini files are intended for and after some research decided the way to use them.

There are 2 main classes for reading and writing to ini files TIniFile and TMemIniFile, but which one should you use?

Basically, I found out that TIniFile should be used to write to the file and TMemIniFile should be used to read from the file. A few people mentioned to me to just use the TMemIniFile and you should not use TIniFile, however I believe the TMemIniFile uses an internal hash table which causes writing to the file to be slow. So there it is, use TIniFile to write and TMemIniFile to read.

Monday, 20 May 2013

How to store application settings in an INI file

Usually when you write a piece of software you want to store off user information about the software, for example window positions and sizes, there are multiple ways of doing this, here is a simple example using an INI file.

uses iniFiles;

procedure TForm.SaveSettings;
var
    iniFile: TIniFile;
begin
    iniFile := TIniFile.Create(GetCurrentDir + '/Settings.ini');
    try
        iniFile.WriteInteger('MAINFORM', 'LEFT', Left);
        iniFile.WriteInteger('MAINFORM', 'TOP', Top);
        iniFile.WriteInteger('MAINFORM', 'WIDTH', Width);
        iniFile.WriteInteger('MAINFORM', 'HEIGHT', Height);
    finally
        iniFile.Free;
    end;
end;

procedure TForm.LoadSettings;
var
    iniFile: TIniFile;
begin
    iniFile := TIniFile.Create(GetCurrentDir + '/Settings.ini');
    try
        Left   := iniFile.ReadInteger('MAINFORM', 'LEFT', Left);
        Top    := iniFile.ReadInteger('MAINFORM', 'TOP', Top);
        Width  := iniFile.ReadInteger('MAINFORM', 'Width', Width);
        Height := iniFile.ReadInteger('MAINFORM', 'Height', Height);
    finally
        iniFile.Free;
    end;
end;

There are 2 procedures here that load and save the forms size and position. The values are stored in the INI file located in the same directory as the executable. Other ways of storing these values would be in the registry or in rare cases you may want to store these sort of settings in a database.