Discussion:
array[0..0] of byte -> invalid typecast
(too old to reply)
KoenDW
2010-04-21 13:34:23 UTC
Permalink
Hello,

I am trying to migrate a component from version 7 to 2009. As could be
expected, some code parts do not compile. It is code from the TScap32-
project which apparently is halted.

I get an invalid typecast on this line:
Move(pOrigDibBmi^, TByteArray(pCopiedDib^)[0], BmiSize);

TByteArray is a type declared as: TByteArray = array[0..0] of Byte;
pCopiedDib is a PChar

I've read that some changes were introduced in Delphi 2009 concerning
pointers and dynamic array.

Can someone help me out?

regards,

Koen
Bart
2010-04-21 13:12:17 UTC
Permalink
Op Wed, 21 Apr 2010 06:34:23 -0700 (PDT) schreef KoenDW
Post by KoenDW
Hello,
I am trying to migrate a component from version 7 to 2009. As could be
expected, some code parts do not compile. It is code from the TScap32-
project which apparently is halted.
Move(pOrigDibBmi^, TByteArray(pCopiedDib^)[0], BmiSize);
TByteArray is a type declared as: TByteArray = array[0..0] of Byte;
pCopiedDib is a PChar
I've read that some changes were introduced in Delphi 2009 concerning
pointers and dynamic array.
Can someone help me out?
regards,
Koen
Doesn't TByteArray(pCopiedDib^)[0] and pCopiedDib^ point to the same
adress in memory (thus making the typecast superfluous)?
Move() doesn't care about what type it is at all.

Bart
--
Bart Broersma
***@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Rudy Velthuis
2010-04-21 23:07:52 UTC
Permalink
Post by KoenDW
Hello,
I am trying to migrate a component from version 7 to 2009. As could be
expected, some code parts do not compile. It is code from the TScap32-
project which apparently is halted.
Move(pOrigDibBmi^, TByteArray(pCopiedDib^)[0], BmiSize);
TByteArray is a type declared as: TByteArray = array[0..0] of Byte;
pCopiedDib is a PChar
That looks wrong to me. Try:

Move(pOrigDibBmi^, PByteArray(pCopiedDib)^[0], BmiSize);
Post by KoenDW
I've read that some changes were introduced in Delphi 2009 concerning
pointers and dynamic array.
The only changes introduced are that you can use pointer arithmetic on
other pointer types than PChar/PAnsiChar/PWideChar too. It is on by
default for PByte, but off by default for all others.

So now you can use:

Move(pOrigDibBmi^, PByte(pCopiedDib)^, BmiSize);

But note that in Delphi 2009, PChar is now PWideChar, so be sure that
you copy to the correct type.
--
Rudy Velthuis http://rvelthuis.de

"I would have made a good Pope."
-- Richard M. Nixon (1913-1994)
Jamie
2010-04-22 11:15:26 UTC
Permalink
Post by KoenDW
Hello,
I am trying to migrate a component from version 7 to 2009. As could be
expected, some code parts do not compile. It is code from the TScap32-
project which apparently is halted.
Move(pOrigDibBmi^, TByteArray(pCopiedDib^)[0], BmiSize);
TByteArray is a type declared as: TByteArray = array[0..0] of Byte;
pCopiedDib is a PChar
I've read that some changes were introduced in Delphi 2009 concerning
pointers and dynamic array.
Can someone help me out?
regards,
Koen
Looks a little over complicated..

Move(pOrgDIbBmi^, pCopiedDib^, BMSize);

Loading...