PDA

View Full Version : Delphi pointer comparation



SesillaAndromeda
18-09-2011, 05:38 PM
How is possible to compare two pointer?

In c is possible to have:

int *P1;
int *P2;

if (P1<P2)
//some stuff

Thanks
Sesilla

arthurprs
18-09-2011, 07:17 PM
You can cast it to a Cardinal, depending on your compiler version.

LP
18-09-2011, 11:36 PM
You can adjust pointers by casting them to PtrInt on FreePascal or NativeInt on Delphi.

However, I would advice that you change your code so that you don't need this comparison. For instance, try comparing actual indices to an array instead. The way you want to compare the pointers is very troublesome; it could be both unpredictable and unreliable.

paul_nicholls
19-09-2011, 12:14 AM
How is possible to compare two pointer?

In c is possible to have:

int *P1;
int *P2;

if (P1<P2)
//some stuff

Thanks
Sesilla

If you want to compare integer values the pointers 'point to', you can do this:


if P1^ < P2^ then
//some stuff

cheers,
Paul

SesillaAndromeda
20-09-2011, 01:41 PM
Thanks to all!

Sesilla