Best Place to get help on converting Delphi 2007 string to Delphi 2009

Where is the best place to get help on converting Delphi 2007 strings to 
Delphi 2009?

The most common problem getting Delphi 7-Delphi 2007 components to compile 
seems to be caused by the new Unicode strings in Delphi 2009.

It would be great if there was some place to go to get help with this. 
Maybe there should be a new group for String conversion where developers 
could ask short questions about conversion.

For example:

Delphi 7 - Delphi 2007
CharArrayPtr = ^CharArray;
CharArray = array[0..MaxInt-1] of Char;
Compiles

Delphi 2009
CharArrayPtr = ^CharArray;
CharArray = array[0..MaxInt-1] of Char;
[DCC Error] xxxTypes.Pas(85): E2100 Data type too large: exceeds 2 GB
Conversion:

Regards,

Bill
0
Bill
9/18/2008 1:57:44 PM
embarcadero.delphi.non-tech 5933 articles. 1 followers. Follow

16 Replies
1486 Views

Similar Articles

[PageSpeed] 15

Bill Miller wrote:

> Where is the best place to get help on converting Delphi 2007 strings
> to Delphi 2009?

I've written an article here:

http://dn.codegear.com/article/38693

that has a lot of information.

You can ask all the questions you want in our forums here.


> For example:
> 
> Delphi 7 - Delphi 2007
> CharArrayPtr = ^CharArray;
> CharArray = array[0..MaxInt-1] of Char;
> Compiles
> 
> Delphi 2009
> CharArrayPtr = ^CharArray;
> CharArray = array[0..MaxInt-1] of Char;
> [DCC Error] xxxTypes.Pas(85): E2100 Data type too large: exceeds 2 GB
> Conversion:

The problem here is that SizeOf(Char) is now 2 bytes, so you are trying
to create an array bigger than the OS can handle.

-- 
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges
0
Nick
9/18/2008 5:22:22 PM
> {quote:title=Bill Miller wrote:}{quote}
> Conversion:

type
  CharArrayPtr = ^CharArray;
  CharArray = array[0..MaxInt div 2-1] of Char;

But if you actually use CharArray as a byte buffer then convert to

  ByteArrayPtr = ^ByteArray;
  ByteArray = array[0..MaxInt-1] of Byte;
0
Aleg
9/18/2008 5:28:53 PM
Aleg Azarousky wrote:

>  CharArray = array[0..MaxInt div 2-1] of Char;

Or better:

CharArray = array[0 .. (MaxInt div SizeOf(Char)) - 1] of Char;

-- 
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges
0
Nick
9/18/2008 5:41:09 PM
> Or better:
> 
> CharArray = array[0 .. (MaxInt div SizeOf(Char)) - 1] of Char;

Of course, it's backward compatible.
0
Aleg
9/18/2008 5:50:45 PM
Nick,

Maybe you need some more examples in another article:

how to handle this:

if assigned(namedblocks.p_OiFilNam) then
      freemem(namedblocks.p_OiFilNam);
    l := strlen(@ptr[pos]);
    getmem(namedblocks.p_OiFilNam, l + 1);
    move(ptr[pos], namedblocks.p_OiFilNam^, l + 1);

Bill
0
Bill
9/18/2008 6:01:01 PM
Bill Miller wrote:

>     getmem(namedblocks.p_OiFilNam, l + 1);
>     move(ptr[pos], namedblocks.p_OiFilNam^, l + 1);

	l + 1 => (l + 1) * SizeOf(Char)

	That's backwards-compatible, too.

	See also:

http://chrisbensen.blogspot.com/2007/11/unicode-sizeof-is-different-than-length.html

-- 
Craig Stuntz · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz/
0
Craig
9/18/2008 6:17:24 PM
Aleg Azarousky wrote:

> Of course, it's backward compatible.

And forwards compatible.  ;-)



-- 
Nick Hodges
Delphi Product Manager - Embarcadero
http://blogs.codegear.com/nickhodges
0
Nick
9/18/2008 6:36:03 PM
Additionally

  l := strlen(pChar(@ptr[pos]));

Won't compile without the type cast.
0
Aleg
9/18/2008 6:36:58 PM
Bill Miller wrote:

> Delphi 2009
> CharArrayPtr = ^CharArray;
> CharArray = array[0..MaxInt-1] of Char;
> [DCC Error] xxxTypes.Pas(85): E2100 Data type too large: exceeds 2 GB

The same as with any other pointer to a maximized out array, IOW:

  XYZArrayPtr = ^XYZArray;
  XYZArray = array[0.. Maxint div SizeOf(XYZ) - 1] of XYZ;
     
So for Char, this becomes:

  CharArrayPtr = ^CharArray;
  CharArray = array[0..MaxInt div Sizeof(Char) - 1] of Char;


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

"Life is pleasant. Death is peaceful. It's the transition that's 
 troublesome." -- Isaac Asimov
0
Rudy
9/18/2008 7:20:44 PM
Bill Miller wrote:

> Nick,
> 
> Maybe you need some more examples in another article:
> 
> how to handle this:
> 
> if assigned(namedblocks.p_OiFilNam) then
>       freemem(namedblocks.p_OiFilNam);
>     l := strlen(@ptr[pos]);
>     getmem(namedblocks.p_OiFilNam, l + 1);
>     move(ptr[pos], namedblocks.p_OiFilNam^, l + 1);


  l := (StrLen(@ptr[pos]) + 1) * SizeOf(Char);
  GetMem(namedblocks.p_OiFilNam, l);
  Move(ptr[pos], namesblocks.p_OiFilNam^, l);

But it would be interesting to see what ptr[] is.
  
-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Obstacles are those frightful things you see when you take your 
 eyes off your goal." -- Henry Ford (1863-1947)
0
Rudy
9/18/2008 7:25:23 PM
> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}

> > if assigned(namedblocks.p_OiFilNam) then
> >       freemem(namedblocks.p_OiFilNam);
> >     l := strlen(@ptr[pos]);
> >     getmem(namedblocks.p_OiFilNam, l + 1);
> >     move(ptr[pos], namedblocks.p_OiFilNam^, l + 1);
> 
> 
>   l := (StrLen(@ptr[pos]) + 1) * SizeOf(Char);
>   GetMem(namedblocks.p_OiFilNam, l);
>   Move(ptr[pos], namesblocks.p_OiFilNam^, l);

I assume l is the length of the string in characters. So to be precise the Craig's suggestion is more reliable.

> But it would be interesting to see what ptr[] is.

Most likely ptr: pChar;
0
Aleg
9/18/2008 7:43:54 PM
Aleg Azarousky wrote:

> > {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> 
> > > if assigned(namedblocks.p_OiFilNam) then
> > >       freemem(namedblocks.p_OiFilNam);
> > >     l := strlen(@ptr[pos]);
> > >     getmem(namedblocks.p_OiFilNam, l + 1);
> > >     move(ptr[pos], namedblocks.p_OiFilNam^, l + 1);
> > 
> > 
> >   l := (StrLen(@ptr[pos]) + 1) * SizeOf(Char);
> >   GetMem(namedblocks.p_OiFilNam, l);
> >   Move(ptr[pos], namesblocks.p_OiFilNam^, l);
> 
> I assume l is the length of the string in characters. So to be
> precise the Craig's suggestion is more reliable.

I don't quite care what l is supposed to be (in my example, it should
be renamed to something like bufsize). In the code I saw l was the size
of the buffer to allocate, minus one. Why calculate twice if you can do
it once?



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

"Talk sense to a fool and he calls you foolish."
 -- Euripides
0
Rudy
9/18/2008 8:16:26 PM
{quote:title=Rudy Velthuis (TeamB) wrote:}{quote}

> > I assume l is the length of the string in characters. So to be
> > precise the Craig's suggestion is more reliable.
> 
> I don't quite care what l is supposed to be (in my example, it should
> be renamed to something like bufsize). In the code I saw l was the size
> of the buffer to allocate, minus one. Why calculate twice if you can do
> it once?

This variable can be used below in the code, say for an iteration in a cycle as limit.
0
Aleg
9/19/2008 5:16:22 AM
{quote:title=Rudy Velthuis (TeamB) wrote:}{quote}

> Why calculate twice if you can do it once?

If a rewrite is allowed then I would suggest to original poster to redesign this part entirely, and to use String type instead of PChar. Let the Delphi care about an allocating/freeing of memory!
0
Aleg
9/19/2008 5:28:04 AM
Aleg Azarousky wrote:

> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> 
> > > I assume l is the length of the string in characters. So to be
> > > precise the Craig's suggestion is more reliable.
> > 
> > I don't quite care what l is supposed to be (in my example, it
> > should be renamed to something like bufsize). In the code I saw l
> > was the size of the buffer to allocate, minus one. Why calculate
> > twice if you can do it once?
> 
> This variable can be used below in the code, say for an iteration in
> a cycle as limit.

As long as I don't see any code using it, I'll asume it was only used
here. <g>

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

"Computers make it easier to do a lot of things, but most of the 
 things they make it easier to do don't need to be done." 
 -- Andy Rooney.
0
Rudy
9/19/2008 9:45:44 AM
Aleg Azarousky wrote:

> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> 
> > Why calculate twice if you can do it once?
> 
> If a rewrite is allowed then I would suggest to original poster to
> redesign this part entirely, and to use String type instead of PChar.
> Let the Delphi care about an allocating/freeing of memory!

That is always a good suggestion.
-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Incrementing C by 1 is not enough to make a good object-oriented
 language."  -- M. Sakkinen
0
Rudy
9/19/2008 9:46:32 AM
Reply: