There have been a lot of questions about a compiler switch to change what type string maps to. Just to avoid any confusion the title of this post say's it all, but here are a few more specifics. String will map to UnicodeString. If you need AnsiString you still can use it, but string will not map to AnsiString.
If you think about it a switch isn't a viable solution. If there were a switch there would be three primary ways of doing it:
1. All generated files would contain both ANSI and unicode code doubling the size of each file.
2. All source files would be compiled twice to generate ANSI and unicode versions of all generated files.
3. The string type would have a run-time switch for ANSI or unicode.
Each of these options has advantages and disadvantages but the fact is each of these options add complexity. The simplest solution is ANSI or unicode. I personally choose unicode.
Tuesday, January 29, 2008
There Will Not be a Compiler Switch for Unicode
Posted by Chris Bensen at 9:00 AM 22 comments
Labels: C++Builder, Delphi, Unicode
Wednesday, January 23, 2008
Unicode: SizeOf(Char) and Sizeof(Byte)
New to Tiburon SizeOf(Char) will not equal Sizeof(Byte). This means that any pointer arithmetic currently being done by casting something to a PChar should be changed to use a PByte. This is a change in the language because all current versions don't allow pointer arithmetic on PByte and of course because Char will be mapped to WideChar instead of AnsiChar.
So if you are going through your code now to get it ready for unicode, I suggest adding {$IFDEF UNICODE} or something equivalent around the code that is ANSI only so you can test it and mark it to be looked at later.
I'm thinking of creating a unicode FAQ where I gather up all the unicode information into one location. Would that be useful for everyone?
Posted by Chris Bensen at 10:00 AM 11 comments
Tuesday, January 22, 2008
Ads
It was brought to my attention that my recent test of placing ads between posts while my revenue increased was annoying. So I've now changed the colors. I like messing around with the ads for various reasons so please humor me. If you find them really annoying just drop my a polite email or comment. I don't mind changing them but I find it really interesting how placement can affect the revenue they generate.
Posted by Chris Bensen at 5:00 PM 9 comments
Thursday, January 17, 2008
Using the Delphi Type Library Importer to Import Microsoft XML
Over the years I've gotten many questions about importing Microsoft XML with the type library importer and why the resulting *_TLB.pas file doesn't match that of Microsoft's documentation. There are a lot of interfaces with the same problem but lets take a closer look at one of them as an example. You can find the documentation for ISAXDXMLReader.getProperty here. The documentation provides the following C++ code for the getProperty function:
HRESULT getProperty(
const wchar_t* pwchName,
VARIANT* pvarValue
);
Notice the type of pwchName. It's type is const wchar_t* which should be const WideString but as you can see after importing the type library you get:
function getProperty(var pwchName: Word;
out pvarValue: OleVariant): HResult; stdcall;
Obviously the codegen is wrong but why is that. If you take a look at the .tlb in Ole View or the Type Library Editor you'll notice the following IDL:
HRESULT _stdcall getProperty(
[in] unsigned short* pwchName,
[out, retval] VARIANT* pvarValue);
Notice the unsigned short*. The type library importer generated it as a var Word. This means the type library is doing exactly what it should be doing.
So either the documentation is incorrect or the .tlb is incorrect.
Posted by Chris Bensen at 11:00 AM 0 comments
Labels: C++Builder, COM, Delphi
Delphi Tips and Tricks: Selecting Tool Palette Items
There is a really easy way of selecting items in the Tool Palette from the keyboard: CTRL + ALT + P then just type the component you want.
Posted by Chris Bensen at 9:00 AM 3 comments
Labels: C++Builder, Delphi, Tips
Friday, January 11, 2008
GUI Testing
A friend sent me this link about GUI Testing which is a funny read. It describes a 9-step process organizations take when testing the GUI of applications. Having been in the industry some time now I find it to be spot on.
Posted by Chris Bensen at 11:00 AM 0 comments
Wednesday, January 9, 2008
Tiburón Will Get New UnicodeString Type
Last year I talked about unicode here, here and here. At that point CodeGear wasn't publicly talking about the implement. But today Allen Bauer wrote a lot of insightful information in this post.
The question that he answers that I've been asked a lot is "are you just using WideString"? here is a quote from Allen's post:
"...There is a new data type. UnicodeString. It will be reference-counted just like AnsiString and unlike WideString which is a BSTR. This new data type will be mapped to string which is currently an AnsiString underlying type depending on how it is declared. Any string declared using the [] operator (string[64]) will still be a ShortString which is a length prefixed AnsiChar array. The UnicodeString payload will match that of the OS, which is UTF16. This means you can, at times, have surrogate pairs for characters. For characters that fall outside the Basic Multilingual Plane (BMP)."
So there you have it. You still have the old faithful AnsiString type but you also have a new UnicodeString type that is UTF16 that will be aliased to string. This means you don't have to change much of your code which is great news. More to come about UnicodeString.
Posted by Chris Bensen at 2:00 PM 5 comments
Labels: Delphi
Friday, January 4, 2008
A Quick Look Back at 2007
Looking back over the Google Analytics statistics this blog has accumulated over the last year, I wanted to bring up a few things I found interesting.
My spelling has gotten better since the first post. I'm sure all the good spellers out there have rejoiced.
Most people read this blog Monday through Thursday. Saturday and Sunday are the slowest days, no surprise there, but Friday isn't far behind.
Google AdSense revenue more than doubled since adding a banner at the top of the site. I don't make much money off the site, but something is better than nothing.
The top 5 locations are:
United States
Germany
United Kingdom
Netherlands
Canada
California alone would be second in the list due to the Silicon Valley and Scotts Valley is the most popular city, so obviously coworkers are one of the most active readers. But there are way more readers located in Scotts Valley then we have employees in CodeGear, so obviously there are some other Delphi fans out there browsing the web from Scotts Valley. In Germany Munich is the most popular location with Berlin a close second. In United Kingdom we have London by a landslide. The Netherlands is a very close to United Kingdom in numbers and Amsterdam has the win for top readership. And in Canada we have Toronto and Montreal.
By far Windows is the king of the Operating Systems, with Mac at 4% and Linux way at the bottom. 5 iPods, 2 iPhones, 1 Nintendo Wii, 1 Playstation Portable and 1 Sun workstation have visited the blog.
The top 5 screen resolutions are: 1280x1024, 1024x768, 1680x1050, 1600x1200, 1280x800.
The posts that become popular sometimes surprises me. Here are the top 5 posts in 2007.
Upgrading Delphi
String Parameters in Delphi
Delphi Tips And Tricks: CoInitialize/CoUninitialize Part III
The Coolest Pull-up Bar
Help Examples
My pull-up bar post was way more popular than I could have possibly imagined. Maybe I should post more about making things such as the French drains I installed in my backyard (which are working fabulously with the current storm), or how I installed a water softener, or maybe even about the remodel of our master bedroom that has taken way way too long. Have a baby and everything is put on hold. Maybe baby tips and tricks would be popular. Anyway, it's got me thinking.
Posted by Chris Bensen at 9:00 AM 4 comments
Thursday, January 3, 2008
Delphi Tips and Tricks: Single Line Comments
A useful feature of the latest versions of Delphi and C++Builder is CTRL + /. This will place a single line comment, //, in front of every line that is selected or that the cursor is on. It will also remove the comment. Very quick and easy.
Posted by Chris Bensen at 4:00 PM 9 comments
Labels: C++Builder, Delphi, Tips
Wednesday, January 2, 2008
January Photo of the Month
Things got a little busy last month and I forgot to post a December photo of the month. So I'm starting the new year off right with a photo I took at Wilder State Park in Santa Cruz. In the background you can see across the Monterey Bay. It was a very clear day. If you happen to read Nature Photographer Magazine you'll find this photo published in the 2008 Spring issue. No Photoshop here, that bee is real!
Posted by Chris Bensen at 1:00 PM 2 comments
Labels: photo
The New Year
Okeydokey, 2007 is in the books. Now it's time to hit the ground running with 2008. I'm back at work getting in the swing of things as if the Holiday's had never happened. I always enjoy going to the beach. It's a Bensen family tradition to visit the beach on Christmas day. These photos were taken on Christmas Day of my daughter.
With 175 posts under my belt and over 15,000 unique visitors in 2007, there are plenty more things to blog about in 2008. Wow, over 15,0000 visitors. I'm just an ordinary guy here so that number seems really high. Cool!
As we work on Tiburón, the next version of Delphi, talk about old technologies that people once thought were dead, COM, and explorer new technologies, this should be an exciting year.
Posted by Chris Bensen at 11:00 AM 0 comments