Friday, 2 September 2016

Delphi Vs Visual Studio

This is a comparison between developing software in Delphi XE+ vs Visual Studio 2015 (C#). I’ve decided not to go to in-depth with regards to syntax or run time dependencies of executables. I have experience in both although I have mainly developed web service and WCF services in C#, and mainly developed desktop applications in Delph, so that might affect some of my opinions.

Delphi Pros

  •          Quick and easy to develop desktop applications.
  •          I prefer the form designer, because I find it easier to use.
  •          Quick to compile projects.
  •          I like the code structure of interface and implementation in the same file.
  •          You can develop mobile apps.


Delphi Cons

  •          Code insight is slow and could be significantly improved.
  •          Some areas of the IDE look dated and it needs investment to keep it up to date with its competitors.
  •          Find declaration does not always work, finding the function or procedure is more time consuming than Visual Studio.
  •          Hard to employ developers as there are not many about.
  •          Code insight is slow to update, for example add a new property to a class and sometimes you need to compile to make that property available for code insight.
  •         Unit testing using DUnit feels old and there has been little development of it over the years.

  

Visual Studio Pros


  •          IDE has a more modern interface, like the option for a dark color theme.
  •          Code IntelliSense is great, and I like the ‘potential fixes’ option which is very useful for adding directive or assembly reference.
  •         Unit testing is easy and integrated into the IDE, making it easy to run tests while you are developing.
  •          Debugging services is easier than when I have developed services in Delphi, this might have changed recently in later versions of Delphi.
  •         Peek definition is a nice feature.

Visual Studio Cons


  •         Slow to start-up.
  •          Sometimes freezes and it is best just to wait.

Tuesday, 21 June 2016

Delphi error XML document must have a top level element. line 0

I have a Delphi application written in XE that consumes a WCF service written in C#, I have been receiving the following error message with one of the methods

XML document must have a top level element. line 0

I managed to fix the issue by making the method in the WCF Service return a value (boolean) if successful. It is possible Delphi does not like WCF Service methods that are one way ([OperationContract(IsOneWay = true)]).

Sunday, 6 September 2015

Slow code insight - How to improve

Over the past couple of weeks I've noticed my code insight has gone slow. It seemed to happen after about 10 minutes of using Delphi, and got slower and slower to a point even typing in a string took over 5 seconds per character. The following reasons could have been the cause for this:

  1. Something in Windows after an update is causing the issue. I believe this to be highly unlikely because all my other software works fine.
  2. The problem seemed to coincide with installing the latest version of Visual Studio Professional (2015). This again seems unlikely.
  3. Something specific to my current project is causing the problem. I think this is the most likely issue, other smaller projects work fine.
I did manage to improve the situation by turning off 'Error Insight' (red swiggle under error in code) in the code insight options. This feature was sometimes useful, but I also found it behaved strangely and reported errors in blank areas of code. I now have to restart Delphi every couple of hours instread of every 20 minutes.

I am still looking at how to improve the situation.

Sunday, 19 July 2015

How to draw an arrow head

I've worked on a few developments that require graphical input form users like CAD, flow control and diagram applications. Here is a snippet of code that draws an arrow head to a line.

This is an example and in real code you might want to pass the arrow head length and width in as parameters.




procedure TMainForm.DrawArrowHead(const x1, y1, x2, y2: integer;
  Canvas: TCanvas);
var
  HeadLength : real;
  HeadWidth : real;
  xbase : Integer;
  xLineDelta : Integer;
  xLineUnitDelta : Double;
  xNormalDelta : Integer;
  xNormalUnitDelta : Double;
  ybase : Integer;
  yLineDelta : Integer;
  yLineUnitDelta : Double;
  yNormalDelta : Integer;
  yNormalUnitDelta : Double;
  OrigBrushColor : TColor;
begin
   OrigBrushColor := Canvas.Brush.Color;
   Canvas.Brush.Color := clBlack;
   xLineDelta := x2 - x1;
   yLineDelta := y2 - y1;
   xLineUnitDelta := xLineDelta / SQRT( SQR(xLineDelta) + SQR(yLineDelta));
   yLineUnitDelta := yLineDelta / SQRT( SQR(xLineDelta) + SQR(yLineDelta));
   // (xBase,yBase) is were the arrow line is perpendicular to base triangle.
   HeadLength := 12;
   HeadWidth := 2;
   xBase := x2 - ROUND(HeadLength * xLineUnitDelta);
   yBase := y2 - ROUND(HeadLength * yLineUnitDelta);

   xNormalDelta := yLineDelta;
   yNormalDelta := -xLineDelta;
   xNormalUnitDelta := xNormalDelta / SQRT( SQR(xNormalDelta) + SQR(yNormalDelta));
   yNormalUnitDelta := yNormalDelta / SQRT( SQR(xNormalDelta) + SQR(yNormalDelta));
   //Draw the arrow tip
   Canvas.Polygon([Point(x2,y2),
     Point(xBase + Round(HeadWidth*xNormalUnitDelta),
       yBase + ROUND(HeadWidth*yNormalUnitDelta)),
     Point(xBase - ROUND(HeadWidth*xNormalUnitDelta),
       yBase - ROUND(HeadWidth*yNormalUnitDelta)) ]);
   Canvas.Brush.Color := OrigBrushCOlor;
end;

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.

Friday, 22 May 2015

Delphi increases in popularity

I've been developing software using Delphi for well over 15 years and for at least the last 10 years I hear all about how Delphi is dead and developers are moving to other languages. I have just looked at the TOIBE index which list software development languages by popularity and Delphi has moved from ranking 15 last year to 13 this year, so this shows that Delphi is going to stay around for some time to come.

Obviously these ranking change constantly and it could be next year Delphi goes back down the list, but I do think it says shows that Delphi is not dead and that all the people who have said 'Delphi is dead' for the last 10+ years are wrong.

Tuesday, 19 May 2015

Prefix class with 'I'

The other week I was looking at some code another Delphi developer had written and noticed that he prefixed classes with 'I' instead of 'T'. In my world the prefix 'I' means its an interface, but he argued that an abstract class is an interface and that all abstract classes should be prefixed with 'I'. I disagreed with him for various reasons, one being that Delphi standard classes do not do this.

Does anyone else prefix their abstract classes with 'I' and only use 'T' for concrete classes?