Archive for the ‘Porting Turbopower Essentials’ Category

TDateTime in Delphi.Net

Wednesday, June 25th, 2008

In Delphi for Win32 the TDateTime type is a Double, but in Delphi.Net it is declared as a record which uses a System.DateTime to hold the date / time value. For the most part this was done in such a way as to be transparent. However, there is one aspect of the new implementation that is not portable between Win32 and .Net.

In both Win32 and .Net a TDateTime that is a member of a class is initialized to a value of zero when the class is created. In Win32 the standard way to test for this was if (FDate = 0). This doesn’t work in .Net programs. You need to cast the date as a Double first. So the equivalent .Net code is if (Double(FDate) = 0). This is at least portable from .Net to Win32 but existing Win32 programs will fail.

Property Editors in Delphi.Net

Monday, June 23rd, 2008

There don’t appear to be any serious gotchas when implementing property editors for your custom components in Delphi.Net.  The only thing that caused me some grief was getting the darn thing to compile.  What you need to do is add Borland.Studio.Vcl.Design.dll to the requires list and change DesignIntf to Borland.Vcl.Design.DesignIntf and DesignEditors to Borland.Vcl.Design.DesignEditors in the uses list.

Interfaces in Delphi.Net

Monday, June 23rd, 2008

While porting the data aware controls in the Essentials component suite I discovered that the CM_GETDATALINK message is no longer used to get the component’s TDataLink reference. VCL.Net now uses the IDataLink interface to do the same thing. Essential’s data aware controls were easily fixed by making them implement the IDataLink interface and removing all references the the CM_GETDATALINK message.

Since I had never come across interfaces used this way in Delphi, I decided to do some reading on the topic. I found the CodeGear documentation on the topic to be a bit sparse for some one, like me, who didn’t already know what they were talking about. Here is my attempt to explain it in somewhat simpler terms.

(more…)

Creating Custom Palettes in Delphi.Net

Friday, June 20th, 2008

Creating my own custom palettes is not something that I have had any real experience with, but the Essentials component suite uses custom palettes so I had to delve into this.  In Win32, you used a TLogPalette record as a template.   You had to allocate memory for a TLogPalette structure large enough to hold the number of palette entries that you were going to need.  Something like this:

(more…)

ShortStrings and Delphi.Net

Friday, June 20th, 2008

The Essentials component suite makes use of fixed length ShortStrings (String[10]) in various places. For the most part this seems to work just fine with Delphi.Net but there are places where the handling of ShortStrings seems to be buggy. There are a couple of reports in Quality Central concerning odd behaviour when using ShortStrings. Here are the links to the reports:

http://qc.codegear.com/wc/qcmain.aspx?d=62961
http://qc.codegear.com/wc/qcmain.aspx?d=62005

My problem was similar to this but different.

(more…)

Variants and Delphi.Net

Thursday, June 19th, 2008

While variant variables (not to be confused with variant records) in Delphi.Net work in the same way as in Delphi for Win32 (at least as far as the end user is concerned) you need to include the Variants unit in your module to make them work.  Failure to do this will result in incompatible type errors when you try to assign from a variant to a regular variable and vice versa.

FillChar and Delphi.Net

Thursday, June 19th, 2008

The old, faithful FillChar function is considered unsafe in a .Net environment and as such is not supported by Delphi.Net.  As understandable as this is, it is a bit of a pain in the backside.  We now seem to be left with no convenient way of initializing arrays.  There is the System.Initialize procedure but from what I can tell from reading the documentation that will work for dynamically allocated arrays and variables but not for static arrays.

Looks like we are left with the old fashioned, but still effective for loop.

Delphi.Net Bug

Thursday, June 19th, 2008

I tripped across a bug in Delphi.Net today. Apparently static array members of classes descended from TPersistent and TComponent will not be created unless the descendant class has a constructor. The constructor doesn’t have to do anything but call the inherited constructor, but it must exist.

Many thanks to Marc Rohloff of TeamB who told me about this bug. I might never have figured it out without his help.

Using wParam and lParam Message Parameters in Delphi.Net

Wednesday, June 18th, 2008

Because .Net looks down on the use of pointers and casting pointers to integers and vice versa, the good folks at CodeGear have chosen to hide the lParam and wParam message parameters from you, choosing instead to cast these values to more appropriate types which they then present to you in an object that is appropriate to the message that you received.  This is great if you want to act on the message yourself, but not so great if you want to pass the message on to some one else using SendMessage or PostMessage.  To do that you need the actual lParam and wParam values.

Fortunately, CodeGear also provides a means of accessing the old, Win32 style TMessage object belonging to the message that you just received.  Just use the OriginalMessage property and you can get access to the raw lParam and wParam values.

Converting Bitmap Resources from .RC format to .resources format

Wednesday, June 18th, 2008

If you want to be able to use bitmap resources using the VCL.Net TBitmap.LoadFromResourceName method you have to have them in .resources format.  This presents a problem when you are trying to convert a Win32 component that has its resources in .RC format.   You can import the .RC file into your component using the $R directive but LoadFromResourceName will not find the bitmaps because they were not imported from a .resources file.  This means that you somehow have to convert the .RC file to a .resources file.  I did quite a bit of searching but was unable to find a utility to do this.  Fortunately, it is quite easy to create your own.

(more…)