Pointers Pointers Pointers 
Author Message
 Pointers Pointers Pointers

Help

I am an C++ programmer, but we want to start using
delphi for user interfaces. My problem comes with
pointer arithmetic.
type
      SomiValue = record
                  _type : Integer;
                  val   : Pointer;
                end;

      PSomiValue = ^SomiValue;
var

   val : PSomiValue;

begin

        GetMem(PSomiValue, 3 * Sizeof(SomiValue));

        { Now I want to use the first somivalue
        In C or C++ I could use the array operands.
        ie *PSomiValue[0]._type := 1;
        In delphi I can't seem to do that , where              
        are all those Pascal gurus I need help }

end;



Fri, 25 Dec 1998 03:00:00 GMT  
 Pointers Pointers Pointers

Var
        val : array[1..3] of PSomiValue;

begin
        for i:=1 to 3 do getmem(Val[i],sizeof(SomiValue);
 Val[i]^._type:=1;
end.



Fri, 25 Dec 1998 03:00:00 GMT  
 Pointers Pointers Pointers

Quote:

>Help

>I am an C++ programmer, but we want to start using
>Delphi for user interfaces. My problem comes with
>pointer arithmetic.
>type
>      SomiValue = record
>              _type : Integer;
>              val   : Pointer;
>            end;

>      PSomiValue = ^tSomiValue;

       tSomiValue = Array[0..$FFF0 div Sizeof(SomiValue)];
Quote:
>var

>   val : tPSomiValue;
>    begin
>            GetMem(PSomiValue, 3 * Sizeof(SomiValue));

>    { Now I want to use the first somivalue
>    In C or C++ I could use the array operands.
>    ie *PSomiValue[0]._type := 1;
>    In delphi I can't seem to do that , where                       are all those pascal gurus I need help }

In Pascal everything has to be declared, so a pointer to a record
does not automatically reference an array as in C.  Change your
declaration of pSomiValue to be a pointer to a type of array and
define the type of array (see changes in above code fragment).

    ...red



Fri, 25 Dec 1998 03:00:00 GMT  
 Pointers Pointers Pointers


Quote:
>Var
>    val : array[1..3] of PSomiValue;

>begin
>    for i:=1 to 3 do getmem(Val[i],sizeof(SomiValue);
> Val[i]^._type:=1;
>end.

isn't more facile: for i := 1 to 3 do New(val[i]); ????

we have: type PSomiValue = ^SomiValue !

Grego

--

/------------------------------------------------------------------




Fri, 25 Dec 1998 03:00:00 GMT  
 Pointers Pointers Pointers


writes:

Quote:

> [...snip...]

>we have: type PSomiValue = ^SomiValue !

There is a long-standing convention in Borland Pascal that the "T" prefix is
used to denote a type, which is replaced by a "P" prefix when denoting a pointer
to that type, so it should be..

type
  PSomiValue = ^TSomiValue;
  TSomiValue = Whatever;

We'll be able to read each others code a lot easier if we all stick to these
convensions.

-- Jay

 ---------------------------------------------------------------------------
| Jason Burgon - author of Graphic Vision, TV-Like GUI for 256 Colour SVGA  |

|                         http://www.en.com/users/grendel/prog/tv_prog.html |
 ---------------------------------------------------------------------------



Sat, 26 Dec 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. pointers, pointers, pointers...

2. Pointers to pointers

3. Beginner needs some pointers with pointers!

4. POINTERS POINTERS...

5. Declaring Far pointers in Pascal, i.e. pointers that point to mem outside of stack!

6. Pointer Arithmetic in TP7.0?

7. test being initialised of pointers and objects

8. pointer to function

9. Turbo Pascal Frequently Asked Questions, a monthly pointer

10. question: BP pointer NEW

11. need pointer to information please

12. FAQ Pointer?

 

 
Powered by phpBB® Forum Software