11

Is there a way to do this ?

I'm currently using 2007 and am looking to upgrade, but its very frustrating trying to get this new version to do anything.

The new behaviour of char, strings and Pchar in xe2 kills virtually every application and third party component I have tried on it.

Is there a compiler option that gives D2007 compatibility. ?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Andy k
  • 1,056
  • 1
  • 11
  • 22
  • 1
    Delphi has AnsiChar, AnsiString, and PAnsiChar types to support old functionality. – Marcus Adams Mar 20 '12 at 16:52
  • You might be asking the most common question ever asked about the Unicode Transition. The answer is 'it's not so bad, just get over it, and port your code'. Almost every commercial and open source component got ported 2-3 years ago. Come on in the water's fine. – Warren P Mar 20 '12 at 18:10
  • 4
    You must be doing it wrong. Unicode porting is pretty straightforward. If you want ANSI, stick to the old versions. If you want the new versions, embrace Unicode. – David Heffernan Mar 20 '12 at 18:52
  • Note what from now on, strings are using twice more memory than in ANSI builds. Buy more DIMMs :-) – OnTheFly Mar 20 '12 at 19:30
  • 2
    @Warren, Its not that simple. I develop EDA and control software for the High Frequency electronics industry. There are standards of interface from data files specs to remote instrumentation control to end user dll interfaces and they all demand 8 bit ASCII transfers and storage. There are hundreds of thousands of lines to code to go through. Why should have to change every string/char/pchar reference? Why did they not introduce Ustring/Uchar etc for Unicode types instead of breaking every-bodies code? – Andy k Mar 20 '12 at 21:10
  • Because in 90%+ case, there will be no problem of using widestring as default string with Unicode support. Also, if those standards of interface do not have Unicode version for so many years, they should be satisfy with 20 century features, which Delphi 2007 can surely handle. – Justmade Mar 20 '12 at 23:42
  • You can stay with an ancient delphi version as long as you like. It's really not so very hard to port. – Warren P Mar 21 '12 at 02:20

3 Answers3

14

There's no way to disable UNICODE in Delphi XE2 (or any version greater than 2009), however there are many resources that can help you to migrate your application:

Community
  • 1
  • 1
RRUZ
  • 134,889
  • 20
  • 356
  • 483
5

If there was a "Ansi switch" for Delphi 2009/2010/XE/XE2 (the unicode versions), you would simply be exchanging the problem you have now, with far worse problems.

For that reason, there can not be a switch. This idea was discussed carefully, I happen to know from first-hand conversations with the people who made the decision, and the decision to break your code was not undertaken without due diligence. There was simply no other way to go. To make Delphi truly Unicode, it was essential to alias String=UnicodeString.

Therefore, you must change all your String declarations to AnsiString, and Char to AnsiChar if you wish to have single-byte non-unicode character and string types in your application code. In most of your code, and in most places, that is not necessary. But where you explicitly need byte-size processing, such as binary protocols over RS232 and RS485, or binary file formats (EDA, etc), you need to change your code.

If you don't want to port your code yourself, pay someone to do it. I ported a huge library of scientific components and applications up myself, and it took me several weeks to test and find all the bugs. Afterwards, I had a reasonable modern codebase that has not broken again since 2009 when I upgraded.

When you get to the XE/XE2 divide, you may encounter some more pain having to do with your code's assumptions that Pointer types are the same size as Integer or Cardinal, which is no longer true in Win64. Again, Delphi guys have no desire to break your code, they're just following sane engineering practices, in that case, Win64 dictates certain things.

Why didn't they change every VCL control property to USTRING instead of String? Why didn't they make every RTL function take both USTRING and STRING and provide overloads?

Because normative Delphi development is now purely Unicode. USTRING is, and would be a special case. String is the native (normative) string type, and it is, in fact, also known now as UnicodeString.

It so happens you were already using a type alias. Strings in delphi 1.0 were limited to 255 characters in length. When they introduced Delphi 2.0, and the long string type, internally called AnsiString, they aliased the existing common type String as String=AnsiString. When we got to Unicode, every VCL component and every VCL method that takes a string still takes a string. However String is now String=UnicodeString.

Delphi 7 already has WideString for example. We don't need a half-way move to unicode. Whether you realize it or not the entire software development world now expects string types to be unicode. Delphi is part of a global phenomenon. The internet is unicode. Your Windows 7 operating system is pure native unicode.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • 1
    Reading the embaracadero unicode white paper convinced me that migration is too horrendous to tackle at this time. I guess I'm stuck with D2007 for the foreseeable future. – Andy k Mar 20 '12 at 23:23
  • Your parallel with Windows 7 is actually quite ironic since we had to ditch 7 due to incompatibility with several of our key tool chains. We only use XP and xp64 now which is a bit sad since it proves Microsoft did have a painless migration path to 64 bits, they just chose not to promote it. – Andy k Mar 21 '12 at 07:58
  • Well, you're painting yourself into several corners then. Enjoy the long slow slide into obsolescence. Windows XP is also native unicode, or didn't you know? – Warren P Mar 21 '12 at 13:04
  • Warren, I am not anti unicode, I am sure there are plenty of people that want unicode. I just can't use unicode in my applications and am frustrated at being forced to use old tools. Even localisation is causing me headaches in delphi, I'm fed up of having to poke a decimal point char into the decimalseparator variable every time I need to do a floattostr or vice versa. I can't be having users save a file in England only to have customers in france complain it doesn't load because delphi is expecting a comma. There should be compiler switches to turn these features off, its just common sense. – Andy k Mar 21 '12 at 13:35
  • You're doing it wrong. You don't need to poke a decimal point char into the decimal separator variable. I predict that there are at least a few other places where you insist on swatting flies with a hammer, if that's how you handle decimal separators. – Warren P Mar 21 '12 at 13:38
  • Warren, I'm not a software engineer, I'm an Engineer that writes software. – Andy k Mar 21 '12 at 15:20
  • I've worked with a lot of Engineers who write software. I totally understand your frustration. The mountain is not coming to you, so you go to the mountain, or you don't. Pinky ring or not. – Warren P Mar 21 '12 at 18:03
0

There is unofficial hack, but it will bring more problems that solve.

Alex
  • 5,477
  • 2
  • 36
  • 56