Tuesday, September 30, 2008

Delphi 2009 Component Palette Categories

In Delphi 2009 the new default behavior for the tool palette is to start with all categories collapsed.

I don't like that behavior at all. I'd prefer the categories I always use to always be expanded. You can change the default behavior in the Tool Palette options. Uncheck the "Auto collapse categories" option.

Tuesday, September 16, 2008

Tips When Porting a Delphi Application to Delphi 2009

Over the past few months I have been keeping notes as I port some components and applications to Delphi 2009, specifically for the purpose of gaining unicode support. While my project is nowhere near complete, I wanted to post some tips. If you are considering porting to Delphi 2009 the CodeGear Developer Network has lots of great documentation describing the new unicode VCL and some unicode basics. This post is simply meant to supliment that information with issues I have encountered and is sprinkled with a few Advantage-specific notes as well.

Database Functionality and Changes

If the AsString method is used on field types that are not ansi-specific you will get unexpected results. For example, if you have a field of type ftBytes and you used to use MyByteField.AsString to set and get these values, you will now be getting unicode characters as opposed to single byte characters. The TBinaryField class has a new AsAnsiString method you will need to use in order to get the results you are used to.

If you read any TBlobStream data into character buffers, those buffers will need to be changed to AnsiChar buffers or TByte buffers, otherwise length/offsets/etc will not be what your existing code expects.

The Delphi database core has been modified and will now parse an SQL statement like the following:

CREATE TABLE c:\mytable ( id INTEGER );

and interpret it as having one parameter called \mytable. It will then automatically add an item to the query component’s Params property. In Advantage execution of the statement will then fail with the error “Error 5110: The parameter number specified was invalid for the statement.”, as really there is no parameter in this statement.

To work around this problem in the Delphi VCL, you must quote the table name. For example:

CREATE TABLE “c:\mytable” ( id INTEGER );

Reading ansi string data from a stream into a string buffer will not work. You need to explicitly read into a temporary ansi buffer first. See below:

The reason the temporary ansi buffer is necessary is because ReadBuffer automatically determines the type of the destination buffer and acts accordingly. If you had stored ansi data in the file or stream, you need to read it into an ansi buffer, not a unicode buffer. If you pass a unicode buffer to ReadBuffer it is going to think you stored unicode data and will read it out as such.

Under the covers CodeGear has changed the TBookmark type from a pointer to TBytes. This will not affect most applications that simply use the GetBookmark and FreeBookmark TDataSet methods. If, however, you are doing anything "goofy" with the pointer you get from GetBookmark, beware. Many of our automated tests needed to be modified to consume the bookmarks in a more generic/standard fashion.

Advantage-Specific Issues

If using the TAdsDictionary component, many of the parameters for functions like TAdsDictionary.AdsDDSetTableProperty are sent via Pointers. If in the past you were casting string variables to PChar, these casts will need to change to send an ansi character buffer now. For example:

AdsDictionary1.SetTableProperty( 'table1', ADS_DD_TABLE_DEFAULT_INDEX, pchar(strDefaultIndex), 8, 0, '' );

Would need to change to:

AdsDictionary1.SetTableProperty( 'table1', ADS_DD_TABLE_DEFAULT_INDEX, PAceChar( AnsiString( strDefaultIndex ) ), 8, 0, '' );

If you use any API’s that return data into char buffers (in Advantage this means ACE API’s), those buffers need to be redeclared as arrays of bytes or an array of AnsiChar, not an array of char (as char is now a unicode char). If using the ACE API a new type called AceChar has been defined and can be used.

Windows API’s

If you are calling Windows API’s and sending in buffers, you may have been using the sizeof function when telling the API how long your buffer is. Those calls need to be changed to use the Length function, as the Windows widechar API’s require the number of characters, not the number of bytes. For example:

must be changed to:

If you were not explicitly calling the “A” functions (for example, SearchPathA), then when compiled in Delphi 2009 your application will now be using the equivalent “W” function (SearchPathW). In many cases this works well, as the Delphi buffers you were passing are now unicode buffers. There are still situations where manual inspection is necessary, however. For example, any API’s that accept a structure will need to be inspected to verify you are populating any string fields in the structure with the expected string type.

Friday, September 12, 2008

Delphi 2009 Conditional Defines

I wasn't going to blog about this, but for the past few months every time I have used Delphi 2009 I have been tricked by this and it's very frustrating.

When you open the project options and head to the familiar "Directories and Conditionals" section be careful. Note it is now under the "Resource Compiler" tree item and does not have anything to do with the old directories and conditionals setting:

You probably don't want to be there. You are likely looking for the old compiler conditionals, which are now hidden under the main "Delphi Compiler" tree item in a property called "Conditional defines":

Thursday, September 4, 2008

Provide Feedback and Vote on Future Features

We have launched a new feedback web page at http://feedback.AdvantageDatabase.com

The site allows you to submit feedback, vote on existing feedback, track the progress of your suggestions and generally provides a single interface for providing feedback to the Advantage team.

We have seeded the site with some of our choices for future features. Check out the site and vote on these features or submit your own new feature requests. If you have submitted feedback in the past but don't see it on the site yet don't worry, we still have more data to upload. Don't hesitate to resubmit your ideas to this new site if you'd like to see them added right away. We will take care of weeding out the duplicates.

Wednesday, September 3, 2008

Updating Static Cursors - Part 2

As I promised in my original post about updating static cursors, here is a screencast demonstrating the technique(9 minute screencast).

I also made a few minor changes to the view and trigger code in the original post, as I noticed I updated the wrong table inside the trigger in the original post. :)

I'll apologize to those with smaller screens in advance for the large desktop I used when recording the screencast. In the future I'll switch to 800x600 before recording these.

Do you have a favorite Help authoring software?

I'm in the process of evaluating help authoring software and was curious if any readers have a favorite I have not yet considered.

My core requirements are as follows:
  • Imports either WinHelp or HTML Help 1.x file format
  • Files are stored uncompressed as either XML or HTML
  • Compiles to HTML Help 1.x, Help 2 (Visual Studio), and WebHelp
  • Supports automated builds (command line compilations)
So far I have evaluated:
  • EC Software's Help and Manual
  • Innovasys HelpStudio
  • MadCap Software's Flare
  • Oxygen XML Editor
  • Just Systems XMetaL
And the contenders are:
  • EC Software's Help and Manual
  • Innovasys HelpStudio
  • MadCap Software's Flare (no Visual Studio help support though...)
If you have experience with any of these packages or war stories to tell I'd love to hear them. You can leave any feedback in the comments section of this post. Thanks!