No, it's not right.

Part of the point of Pascal/Delphi is to protect us from ourselves, by 
enforcing a bit of structure.  I find this a great blessing!

Here's how to do what you want:

type
  Tarray10 = array [1..10] of integer;
  ptr10 = ^Tarray10;

var
  a: Tarray10;
  pi: pointer;
  i: integer;

  pi := address (a);
  for i := 1 to 10 do
    ShowMessage (format ('%d', [ptr10(pi)^[i]]));

In other words, you can typecast any pointer into a pointer to a specific 
type of object.

A better way to do what you might be trying to do is to use open array 
parameters.  Then the compiler will pass the address of the array along with 
its size.  And both you and the compiler will know the type of the array 
elements.

Or, if for some reason pointers are "just perfect" for what you are doing, 
how about declaring a specific pointer type (like ptr10 above), so the 
compiler can help make sure you don't wander off into never never land?

Or are you trying to deal with C-like languages (or Windows) that just pass 
you an address, and hope you know what to do with it?

Rainer


----- Original Message ----- 
From: "Jack" <[EMAIL PROTECTED]>
To: "'Borland's Delphi Discussion List'" <[email protected]>
Sent: Wednesday, January 18, 2006 10:39 PM
Subject: Pointer Operation?


> Hello all,
>
> I thought pointer Delphi was as flexible as pointers in C.
> I just realize that it is not. Or I haven't figured out how
> to use pointers.
>
> In C, I can randomly access any element in a memory block.
> For example, I can do this:
>
>  int a[10], *pi, i;
>  pi = a;
>  for(i = 0; i < sizeof(a); i++)
>    printf("%d\n", *(p + i));
>
> Is it possible to access memory in this fashion
>
>  *(p + i)
>
> using pointers in Delphi? It seems that it's only possible
> with PChar, but not for pointers for any other data types.
> Is that right?
>
> -- 
> Best regards,
> Jack
>

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to