Board index » delphi » Array with pointer variable access

Array with pointer variable access

Hi!

I've got a question with and pointer as array variable:

type
        Data_Rec = record
           V : byte;
        end;

        ryData_Rec = array[1..10,1..10,1..10] of Data_Rec;

        ptrData_Rec = ^ryData_Rec;

var    DataRecptr     : ptrData_Rec;

----
new(DataRecptr)
----

Assume I want to read/write the [1,1,1] : array value of V; how do I
access it?
I assumed it would be DataRecPtr^[1,1,1].V .......

/tj

 

Re:Array with pointer variable access


Quote
Thomas Jonsson wrote:
> type
>         Data_Rec = record
>            V : byte;
>         end;

>         ryData_Rec = array[1..10,1..10,1..10] of Data_Rec;

>         ptrData_Rec = ^ryData_Rec;

> var    DataRecptr     : ptrData_Rec;

> ----
> new(DataRecptr)
> ----

> Assume I want to read/write the [1,1,1] : array value of V; how do I
> access it?
> I assumed it would be DataRecPtr^[1,1,1].V .......

And what makes you think it isn't DataRecPtr^[1,1,1].V ?

Re:Array with pointer variable access


Quote
> Type Data_Rec   = record
>                     V : byte;
>                   end;
>      ryData_Rec  = array[1..10,1..10,1..10] of Data_Rec;
>      ptrData_Rec = ^ryData_Rec;
> var  DataRecptr  : ptrData_Rec;

> ----
> new(DataRecptr)
> ----

> Assume I want to read/write the [1,1,1] : array value of V; how do I
> access it?
> I assumed it would be DataRecPtr^[1,1,1].V .......

   Yes, that's how.  Didn't you try it?  (It's easy enough to do...)
   This is an impractical record definition to use, since you can define
the array type as Byte and leave out the Data_Rec definition.  Unless
this is an academic or school exercise, you're doing much more than this
seems to require.

Re:Array with pointer variable access


"Thomas Jonsson" <Thomas.Jons...@mailbox.hogia.net> skrev i meddelandet
news:38A14A5B.8BAFD8E1@mailbox.hogia.net...

Quote
> Hi!

> I've got a question with and pointer as array variable:

> type
>         Data_Rec = record
>            V : byte;
>         end;

>         ryData_Rec = array[1..10,1..10,1..10] of Data_Rec;

>         ptrData_Rec = ^ryData_Rec;

> var    DataRecptr     : ptrData_Rec;

> ----
> new(DataRecptr)
> ----

> Assume I want to read/write the [1,1,1] : array value of V; how do I
> access it?
> I assumed it would be DataRecPtr^[1,1,1].V .......

> /tj

It is.

I pasted the code in TP7, added a Begin, Write(); and an End.

The only problem was a missing ; at the end of the new() statement.
The compiler reports this at the next line. Did that fool you?

--
/GreenGhost
---
http://hem.passagen.se/guffa/en
---
kill the spammer to mail me

Other Threads