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.

Friday 17 May 2013

Delphi XE4 - The Future Of Software Development

I have been using Delphi for some years now and have also done development with XCode and DotNet, so was very interested in the latest version of Delphi. It seems to do something unique, you can develop software to be deployed to various different devices and operating systems. From what I have seem developers are successfully using Delphi to produce Apps for iPhone and iPad, the surprising thing is that they are true native apps and do not rely on any virtual machine like Mono.

It does sound almost like development nirvana, where you can develop the business code and from a single code base deploy to different operating systems and devices, this surely is the future of software development. Recently when I saw demos of PhoneGap I thought this was the future, but after reading an article about Facebook and their problems with HTML5 and the fact they are moving back to native apps, I was not sure which way was the future, HTML5, PhoneGap, Mono or XCode, Android and DotNet. I have not used XE4 yet, but I am looking forward to using it and exploring what potential it might have.