Tuesday, 31 December 2013

Best Delphi Calendar Planner Component?

I current use a very out of date calendar/planner component in part of the software I develop. I have been looking for something to replace this and can only see 2 possible candidates:

  • DevExpress VCL Calendar
  • TMS Software TPlanner component.
Does anyone know of any other components, or have experience of these and can give advice on which is best?

The requirements for the component are:

  • Needs a month, week and day view, it is possible that this changes to just week view.
  • Different types of entries into the calendar, with different colours.
  • Single day view, with option to specify what is displayed in the header.
  • Need to dynamically create multiple instances of the calendar, or some way of displaying multiple calendars similar to MS Outlook.
  • Drag and drop functionality

Tuesday, 29 October 2013

Running Delphi XE in Parallels Desktop on iMac

I currently use Parallels Desktop to run a Windows VM on my iMac, this works great for most applications, however there are a couple of issues I have found with Delphi.
  1. The some of the shortcut keys do not seem to work.
  2. Function keys required pressing FN key as well as function key.
  3. For some reason the cap locks gets pressed on the VM, meaning I have to open the on-screen keyboard to remove it.
The second issue is easy to fix with going to the system preferences and selecting the use all F1.. option.

Monday, 28 October 2013

Delphi XE5 - The quickest way C# developers can produce Apps

With Delphi XE5, a software developer can produce apps for both iOS and Android from the same code base. But which developers will want to do this?

If you are an iOS developer, it is most likely you are comfortable just developing app for Apple devices and that the company you work for employs Android developers for the Android version and vis versa. And you have no need or want to learn a new language to get the same results.

However, if you are a C# developer then Delphi XE5 might be the quickest way to develop Apps. I found moving from Delphi to C# very easy and after 1 day was developing C# web services. I also found it easy switching back to Delphi after using C# for some months.

So if you are a .Net developer then I would recommend you at least have a look at Delphi XE5.

Thursday, 22 August 2013

DevExpress Quantumgrid Header Height

I have had a problem recently using a DevExpress Quantum Grid which has the column filters enabled and also the ability to drag and drop. I needed a way to get the header height so it would ignore the begindrag. The after trying a few things this is the best way I found to get the header height.

iHeaderHeight := GridView.ViewInfo.HeaderViewInfo.Bounds.Bottom -

Friday, 16 August 2013

You can now develop software for both iOS and Android

I've just read on the Embarcadero blog that you can take an iOS app developed in Delphi and retarget it to work as an Android app. Delphi for Android is still in beta, but this is a significant step to developing software in a single language and deploying it multiple platforms, and importantly the software run natively. If this works as well as they give the impression, Delphi will have solved one of the biggest issues with software development, that is employing different developers to develop similar software for different platforms. Because of this Delphi must surely become more popular.

Thursday, 18 July 2013

How NOT to handle exceptions

Just been working with some code and saw this little gem.

  {Some code}

This is a good example of the developer being lazy and not being bothered to do something better. Can you imagine the user ringing up support and saying they are getting a 'error' message, it's not even with a capital 'E'. 

There are a couple of issues I have with this bit of code. Firstly I have a rule that showmessage() is used while developing and should be removed when a deployment build is done, if a message needs to be displayed it should be in an message dialog (MessageDlg). The reason for this is that a message dialog looks better with icons specify what the message is, I use GExperts to create the code. Also, when developing I can quickly search for 'showmessage' and can see what messages need to be removed, this means there are no embarrassing debug messages displayed to the user.

Secondly is the message just says error, which it not helpful to the user or the developer when it is reported. The developer could have done something better by giving a more useful message like 'An error has occurred while...', with what the operation is doing. The developer could have also included the exception message like the following.

  {Some code}
   on e: exception do
     MessageDlg('An error has occured in...' + e.Message,                mtError, [mbOK], 0);

Friday, 5 July 2013

Delphi XE4 - The future of software development?

Delphi XE4 - The future of software development?: I have been working in software development for 15 years and have seen some changes, but nothing as much as what has happened recently. Over...

Monday, 1 July 2013

Delete files with a wildcard

Here is how to delete files with a wildcard. It requires SysUtls in the uses clause.

procedure DeleteFiles(FilePath, Wildcard: string);
var cSearchRec: TSearchRec;
    iFind     : integer;
    sPath     : string;
    sPath := IncludeTrailingPathDelimiter(FilePath);
    iFind := FindFirst(sPath + Wildcard, faAnyFile, cSearchRec);
    while iFind = 0 do
        DeleteFile(sPath + cSearchRec.Name);
        iFind := FindNext(cSearchRec);


In the while loop you can add additional conditions, like only files that have a specific prefix e.g.

if Pos(fPrefix, Copy(cSearchRec.Name, 0, Length(fPrefix))) > 0 then

Friday, 21 June 2013

Delphi After Resize Event

Here is the way to handle what happens after a user has resized a form. This works fine for standard forms, but does not work for forms within a form.

procedure WMEXITSIZEMOVE(var Message: TMessage); message      WM_EXITSIZEMOVE;

procedure TForm1.WMEXITSIZEMOVE(var Message: TMessage);
    ShowMessage('Just Resized');

I would like to know if there is a way to capture an event when resizing a form in a form.

There is also a similar Windows message for when a user starts to resize a form, which is WM_ENTERSIZEMOVE.

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;
    iniFile: TIniFile;
    iniFile := TIniFile.Create(GetCurrentDir + '/Settings.ini');
        iniFile.WriteInteger('MAINFORM', 'LEFT', Left);
        iniFile.WriteInteger('MAINFORM', 'TOP', Top);
        iniFile.WriteInteger('MAINFORM', 'WIDTH', Width);
        iniFile.WriteInteger('MAINFORM', 'HEIGHT', Height);

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

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.

Tuesday, 9 April 2013

How to correctly free a thread

There are 2 ways to free a thread, below are both, but my favourite way is to explicitly free the thread as I may want to reference something after the thread is terminated, but before it is freed.

Explicitly free the thread 
1) Set the 'FreeOnTermiate' property to false, this can be done when your thread class is created. 
2) In the execute procedure check for the terminate property e.g.

while not Terminated do
     // execute code

3) When you want to free the thread do something like:


Easier way to free the thread
1) Set the 'FreeOnTermiate' property to true.
2) When you want to free the thread just call:


Wednesday, 3 April 2013

How to use an animated GIF in Delphi

In the latest versions of Delphi you can easily use animated GIFs, here are the steps to add one to a form.

  1. Add a standard TImage component.
  2. In the picture property select the GIF file using the ellipsis.
  3. The TGifImage will require GIFImg adding to the uses clause.
  4. In code to set the animation going do the following:
(Image1.Picture.Graphic as TGIFImage).Animate := True;

Tuesday, 2 April 2013

Retrieving a system color

I had a problem recently and needed to set a font colour depending what was set as a system colour, in Delphi this ended up being very easy. To get say the highlight colour just do the following:


This returns the colour as a TColor, I then used this value in a previous function to determine whether is was light or dark and then set the font colour accordingly. This will require 'Windows' and 'Graphics' in the uses clause. The 'color_highlight' is a constant, go to where it is declared in the windows unit to see the other options.

Tuesday, 12 March 2013

Delphi XE After 1 year

I have now been using Delphi XE now for 1 year and I think it is the best version of Delphi I've used. I have 15 years of experience using various versions of Delphi from the stable Delphi 5 to the terrible Delphi 2005 and more recently Delphi 2006 and 2010.

Here are some pros and cons of this version of Delphi.

  • IDE layout is good and similar to Visual Studio and other development environments.
  • Quick to run, however this might be due to the PC I am running it on (8 MB RAM).
  • Code completion works really well.

  • Cost of the product, Delphi is still very expensive
  • Help is not complete, have come across some help which requests more information from the user (TDataSet.CopyFields).
  • You will need a fairly large screen, working on a small monitor will be annoying.
Soon I will be moving to XE3, which will hopefully have more features and will still be as stable as XE.

Thursday, 7 March 2013

Time to string function

Here is a very simple time to string function.

function TimeToStr(dTime: Double): string;
  Result := Format('%4.2f', [dTime]);

Thursday, 28 February 2013

Iterate through controls on a form

Here is how to iterate through all the controls on a form, this is very useful for setting a property value of more than one control, for example the enabled property.

procedure IterateControls(AControl: TControl);
        iControl: Integer;
        if AControl = nil then
        if AControl is TWinControl then
            for iControl := 0 to TWinControl(AControl).ControlCount - 1 do

        // Do Control stuff here
        AControl.Enabled := false;

Where you want to set the control property value it is possible to check for the class something like this.

if (AControl is TButton) then
   (AControl as TButton).Enabled := false;

And, of course the boolean value can be passed as a parameter to the procedure.

FireMonkey Retina Detection

Just read that with FireMonkey it will detect if the device is a retina display and if the property BitmapHighRes is set it will use this image over the standard Bitmap property image. This sounds like it should make things easier than xCode, because you do not have to name them with the @2x included in the filename. I just hope this supports PNG files.

Tuesday, 29 January 2013

Delphi Toolbar Ordering Problem

I am currently using Delphi XE and have noticed an issue with the toolbar component (TToolbar) and the ordering of the buttons. What happened is that I added a toolbar to a form and then added some buttons, all worked fine, but when I reordered the buttons then set them back to the original order the properties when selected did not match the button selected. For example I would select a button and change the enable property and it would change another button to enabled or disabled. The fix for this issue is to add a new button and remove it, adding a new button must do some sort of re-indexing of the buttons.

Sunday, 20 January 2013

FireMonkey Transparent Theme

I saw in a post that FireMonkey has a theme for transparent LCD screens (http://www.youtube.com/watch?v=pVCeduZRMkc). The theme looks impressive and like something out of the film Tron, however I don't know how well it will work with transparent screens, the controls are the standard set which I don't think will work that well on touch screens. I think for touch screens there needs to be a set of new controls developed.