delphi 2006 code in delphi 2010

hello, 

is there any option to make delphi 2006 code work in delphi 2010? something like in java IDEs where you can define the code level you like to use?

the problem is, that i made a project with 2006 and sent it to my customer. they got 2010 and it compiles fine, but it just doesn't work. it deals with en-/decryption of text, we assumed, that it has something to do with ansi vs. unicode strings... but we cant find the exact position where the error occurs.

i am a bit dissapointed, because everywhere i read that the new IDE will always be downwards compatible and so on.. but in reality, it doesnt work..

but i still hope there is a magic checkbox or so, to get my project to work in delphi 2010...

thanks for any help!

best wishes
0
Thomas
10/20/2009 10:51:42 PM
embarcadero.delphi.ide 3925 articles. 0 followers. Follow

10 Replies
1661 Views

Similar Articles

[PageSpeed] 44

Thomas Schmidt wrote:

> 
> hello, 

Hi Thomas,


> 
> is there any option to make delphi 2006 code work in delphi 2010?
> something like in java IDEs where you can define the code level you
> like to use?
> 
> the problem is, that i made a project with 2006 and sent it to my
> customer. they got 2010 and it compiles fine, but it just doesn't
> work. it deals with en-/decryption of text, we assumed, that it has
> something to do with ansi vs. unicode strings... but we cant find the
> exact position where the error occurs.

Delphi 2010 is unicode and Delphi 2006 is Ansi.
In Ansi world 1 char = 1 byte
In Unicode world 1 char may be = 2 bytes

That is the problem you are having.

> 
> i am a bit dissapointed, because everywhere i read that the new IDE
> will always be downwards compatible and so on.. but in reality, it
> doesnt work..

In IDE all is compatible, in your code you should make sure you have
all done right.

> 
> but i still hope there is a magic checkbox or so, to get my project
> to work in delphi 2010...

I think the shortest path is make your en-/decryption code params =
PAnsiString, AnsiString, PAnsiChar, AnsiChar.

> 
> thanks for any help!
> 
> best wishes

Cesar Romero
0
Cesar
10/20/2009 11:02:37 PM
> {quote:title=Cesar Romero wrote:}{quote}
> 
> I think the shortest path is make your en-/decryption code params =
> PAnsiString, AnsiString, PAnsiChar, AnsiChar.
> 
> > 
> > thanks for any help!
> > 
> > best wishes
> 
> Cesar Romero

hello cesar,

thanks a lot for your fast answer! 
where do i enter these code params in delphi 2010?

kind regards
0
Thomas
10/21/2009 12:16:59 AM
Thomas Schmidt wrote:

> > I think the shortest path is make your en-/decryption code params =
> > PAnsiString, AnsiString, PAnsiChar, AnsiChar.
> > 
> > > 
> > > thanks for any help!
> > > 
> > > best wishes
> > 
> > Cesar Romero
> 
> hello cesar,
> 
> thanks a lot for your fast answer! 
> where do i enter these code params in delphi 2010?

Hi Thomas, 

It is not in Delphi itself, it is in your library code:
It was just a suggestion and you should take care of what you are doing:

Eg:

function DoCrypt(Value: PChar): PChar;

you should change to

function DoCrypt(Value: PAnsiChar): PAnsiChar;

Please check Nick Hodges articles:

Delphi in a Unicode World Part I: What is Unicode, Why do you need it,
and How do you work with it in Delphi?
http://dn.codegear.com/article/38437

Delphi in a Unicode World Part II: New RTL Features and Classes to
Support Unicode
http://dn.codegear.com/article/38498

Delphi in a Unicode World Part III: Unicodifying Your Code
http://dn.codegear.com/article/38693



Cesar Romero
0
Cesar
10/21/2009 12:27:16 AM
<Thomas Schmidt> wrote in message news:174957@forums.codegear.com...

> is there any option to make delphi 2006 code work in delphi 2010?
> something like in java IDEs where you can define the code level you
> like to use?

There is no such functionality in Delphi (or any other natively compiled 
language, for that matter).

> the problem is, that i made a project with 2006 and sent it to my
> customer. they got 2010 and it compiles fine, but it just doesn't work.

Can you be more specific about what exactly is not working correctly? 
Changes are, your code is making assumptions about character sizes and 
string encodings and such that are no longer true in 2010's Unicode 
environment.

> it deals with en-/decryption of text, we assumed, that it has something to 
> do
> with ansi vs. unicode strings...

Possibly.  Hard to saw for sure without seeing the actual code.

> i am a bit dissapointed, because everywhere i read that the new IDE will
> always be downwards compatible and so on..

That was true in older Ansi environments, before everything moved to 
Unicode.  There are things in Ansi code that have to be updated, or 
re-written, when dealing with Unicode.  It is not a 1-to-1 translation.

> i still hope there is a magic checkbox

Nope.

> to get my project to work in delphi 2010...

You will have to fix the bugs (and you do have bugs) in your code.

-- 
Remy Lebeau (TeamB)
0
Remy
10/21/2009 1:15:33 AM
"Cesar Romero" <cesar@liws.com.br> wrote in message 
news:174959@forums.codegear.com...

> Delphi 2010 is unicode and Delphi 2006 is Ansi.
> In Ansi world 1 char = 1 byte
> In Unicode world 1 char may be = 2 bytes

The number of bytes depends on the encoding used for the string.  A UTF-16 
string is always 2 bytes per Char, but a UTF-8 string can be between 1-4 
bytes, and an Ansi string can be however many bytes the associated codepage 
actually needs (usually 1-2, maybe 3, but can be more).

> I think the shortest path is make your en-/decryption code params =
> PAnsiString, AnsiString, PAnsiChar, AnsiChar.

That is certainly an option.  You just have to be careful if the source data 
is not an AnsiString to begin with, otherwise a data conversion will occur, 
potentially losing data if non-ASCII characters are being used.

-- 
Remy Lebeau (TeamB)
0
Remy
10/21/2009 1:18:42 AM
Thomas Schmidt wrote:

> thanks a lot for your fast answer! 
> where do i enter these code params in delphi 2010?

Hi Thomas,

Check the links in this thread:
http://stackoverflow.com/questions/1598211/delphi-conversion-unicode-issues



Cesar Romero
0
Cesar
10/21/2009 2:07:12 AM
I ran into a similar problem a while ago, also don't stare yourself blind on the encryption ... If you store it in a database where you can define your set make sure it is in UTF8 in the database. Which was my actual problem, not the encryption of a password :)
0
Kristof
10/21/2009 5:54:36 AM
Thomas Schmidt wrote:

> hello, 
> 
> is there any option to make delphi 2006 code work in delphi 2010?
> something like in java IDEs where you can define the code level you
> like to use?
> 
> the problem is, that i made a project with 2006 and sent it to my
> customer. they got 2010 and it compiles fine, but it just doesn't
> work.

You are hopefully aware of the fact that between Delphis 2007 and 2009,
strings were changed to be Unicode and that characters are and strings
now have 2-byte elements?

They can't just recompile with D2010, unless your code was made Unicode
ready. So get 2010 and do that.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"A nation is a society united by a delusion about its ancestry
 and by common hatred of its neighbors."
 -- William R. Inge
0
Rudy
10/21/2009 11:38:04 AM
thanks for your help! it works now!
0
Thomas
10/30/2009 1:04:18 AM
Hello,

similar problems I have here.
The code in Delphi 2006 looks like this and works fine:
{code}
   Header : string[100];
   version : byte;
   ...
   Header := 'Data ' + EditComment.Text;
   Header[100] := CHR (version);    <-- fails here: CHR command returns AnsiChar
   BlockWrite (FajlStream, Header[1], 100);
{code}

This code in 2010 triggers: +[DCC Error] main.pas(2285): E2010 Incompatible types: 'AnsiChar' and 'Char'+

The weirdest thing is, Help file says: *function Chr(X: Byte): Char;*  but compiler uses AnsiChar.

I must keep the file (where i write this string to) format fixed, because this file is interchanged between different applications.
Have tried with Array of char and similar but no luck.

Now I am trying with *Header : TCaption* and we will see what happens...
0
Aljaz
7/21/2010 7:32:40 AM
Reply: