Archive for September, 2008

Using Delphi Sets in C++ Builder

Monday, September 15th, 2008

I find myself having to do a project in C++ Builder. I have been using Delphi since Delphi 2 but have never had to do a VCL project using C++ Builder before. Mostly, it isn’t a problem. Just mentally convert from Delphi syntax to C++ syntax and away you go. Unfortunately, sometimes you run across something that is an integrated part of the Delphi language that has to be emulated in some other way in C++. Sets are one of those things. (more…)

Indy URL Encoding Bug

Saturday, September 13th, 2008

The TIdURI.ParamsEncode method in the version of Indy that ships with Rad Studio 2007 fails to encode all restricted characters. According to RFC1738:

   Thus, only alphanumerics, the special characters "$-_.+!*'()," (double
   quotes excluded ed.), and reserved characters used for their reserved
   purposes may be used unencoded within a URL.

Unfortunately, rather than encoding everything that is not allowed in the above list, ParamsEncode tries to identify specific characters which should be encoded, and the list that it uses in incomplete. Some snippets from the code illustrate my point:

UnsafeChars = ‘*#%<> []’; {do not localize}

if ((CharIsInSet(ASrc, i, UnsafeChars)) or (not (CharIsInSet(ASrc, i, CharRange(#33,#128))))) then
begin {do not localize}
Result := Result + ‘%’ + Sys.IntToHex(Ord(ASrc[i]), 2); {do not localize}

So ParamsEncode only encodes those characters that are in UnsafeChars or those that fall outside the range #33..#128. Unfortunately, several restricted characters (like double quotes) are inside the range #33..#128 and are not included in UnsafeChars and hence to do not get encoded. Bummer.

As an expedient fix I have taken to calling ParamsEncode and then fixing the characters that got missed in my own code. Longer term, I want to fix ParamsEncode, but that is for another article when I have more time.

Sending Mail with Indy’s TIdSmtp Component

Wednesday, September 10th, 2008

I recently had cause to port an application from the old TurboPower Internet Pro SMTP component to Indy’s TIdSmtp component. Overall I have to say that I like the Indy components better but the documentation leaves a lot to be desired. It is hard to believe that a 4,800 page document could tell you so little about what you really need to know.

Where I really ran into problems was in the very area that was the reason that I was migrating from InetPro. Encrypted connections. No where in the various manuals do they tell you how to make this work. Here is what I have managed to find out.