Board index » delphi » Pointers Pointers Pointers

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;

 

Re: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.

Re:Pointers Pointers Pointers


Quote
In article <31E0AE46....@BSW.CO.ZA> jacques wrote:
>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

Re:Pointers Pointers Pointers


On Mon, 08 Jul 1996 11:06:36 +0200 you wrote:

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

--

/------------------------------------------------------------------
Gregorio Kus    Gr...@RMnet.it                 Gr...@{*word*104}space.org
ROMA, Italy     http://www.RMnet.it/~grego     Gr...@FreeNet.hut.fi

Re:Pointers Pointers Pointers


In article: <1996Jul8.232248.29...@arl.mil>  Gregorio Kus <Gr...@rmnet.it>
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  |
| g...@jayman.demon.co.uk   ftp://SimTel/msdos/turbopas/gv4svga1.zip          |
|                         http://www.en.com/users/grendel/prog/tv_prog.html |
 ---------------------------------------------------------------------------

Other Threads