Board index » delphi » POINTERS POINTERS...

POINTERS POINTERS...

I got a problem here.. I have defined a pointer like this:

var    vaddr            : word;
       vaddrp           : pointer;

begin
  getmem(vaddrp,64000); vaddr:=seg(vaddrp^);

[cut]

now.. if I want a part of the pointer, HOW DO I DO? I thought it was
like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
GREATFULL!

 

Re:POINTERS POINTERS...


Quote
Erik Lundh <may...@algonet.se> wrote:
>I got a problem here.. I have defined a pointer like this:
>var    vaddr            : word;
>       vaddrp           : pointer;
>begin
>  getmem(vaddrp,64000); vaddr:=seg(vaddrp^);
>[cut]
>now.. if I want a part of the pointer, HOW DO I DO? I thought it was
>like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
>GREATFULL!

You need to define an array of 64000 chars, and getmem() that array.

Re:POINTERS POINTERS...


Quote
Erik Lundh <may...@algonet.se> wrote:
>I got a problem here.. I have defined a pointer like this:
>var    vaddr            : word;
>       vaddrp           : pointer;
>begin
>  getmem(vaddrp,64000); vaddr:=seg(vaddrp^);
>[cut]
>now.. if I want a part of the pointer, HOW DO I DO? I thought it was
>like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
>GREATFULL!

you could write a little in-line assembly (if you're using tp) routine
that takes in a pointer type as a paramater and have the routine
return the segment and/or the offset. if you pass the pointer as a
value paramater than just read the segment or offset off the stack.

hope this helps,
dave

Re:POINTERS POINTERS...


Quote
Erik Lundh wrote:

> I got a problem here.. I have defined a pointer like this:

> var    vaddr            : word;
>        vaddrp           : pointer;

> begin
>   getmem(vaddrp,64000); vaddr:=seg(vaddrp^);

> [cut]

> now.. if I want a part of the pointer, HOW DO I DO? I thought it was
> like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
> GREATFULL!

You have an untyped pointer, so the information you'd get when you dereference it is
undefined.  The best solution would probably be:

type
  Tvidscreen = array[0..63999] of byte;
  Pvidscreen = ^Tvidscreen;

var
  vaddrp : Pvidscreen;

begin
  new (vaddrp);
  vaddrp^[32000] := 15;
  {...}
  dispose (vaddrp);
end;

I just want to make one extra point here.  From what I can tell, you're using this as a
buffer page for graphics, specifically mode 13h.  Now, you're assigning the segment of
vaddrp^ to vaddr.  IMHO, do not, do not, DO NOT do this.  When you define a block on the
heap, you can not assume that the offset it 0.  In TP7, it could be 0 or 8 (and I think
earlier versions may be 0 or 16).  So, just using the segment has a chance for pointing
in the vicinity of the memory block, not to the block itself.  This can cause unexpected
bugs.  If you're going to use a pointer, use the whole pointer.

If you're using BASM, you can use "les di,[ptrname]" to load a pointer, and in regular
TP, you can use pointer arithmetic.

--
Scott Earnest                      | _,-""-_,-""-_,-""-_,-""-_,-""-_,-" |
set...@ix.netcom.com (primary)     | We now return you to our regularly |
siny...@{*word*104}space.org (alternate) | scheduled chaos and mayhem. . . .  |

Re:POINTERS POINTERS...


Quote
>   I got a problem here.. I have defined a pointer like this:

>   var    vaddr            : word;
>          vaddrp           : pointer;

>   begin
>     getmem(vaddrp,64000); vaddr:=seg(vaddrp^);

>   [cut]

>   now.. if I want a part of the pointer, HOW DO I DO? I thought it was
>   like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
>   GREATFULL!

Hi, there!

    This problem is not a problem !!!

    You could simply define another pointer and then load address in it
    via function PTR(segment,Offset:Integer):Pointer

EXAMPLE: You want to access position 32000!

var
  vaddr:word;
  vaddrp:pointer;
  other_pointer:pointer;
begin
  getmem(vaddrp,64000);
  ......
  do anything
  .......
  other_pointer:=Ptr(vaddr,32000);

   ***
end.
[cut]

After that you can "other_pointer" will contain address to 32000'th item!

Hope, it will help ya!

bye.

Re:POINTERS POINTERS...


In <3245A50D.5...@algonet.se>, Erik Lundh <may...@algonet.se> writes:

Quote
>I got a problem here.. I have defined a pointer like this:

>var    vaddr            : word;
>       vaddrp           : pointer;

>begin
>  getmem(vaddrp,64000); vaddr:=seg(vaddrp^);

>[cut]

>now.. if I want a part of the pointer, HOW DO I DO? I thought it was
>like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
>GREATFULL!

Do you need to access it as bytes or words?

step 1.
    Define a TYPE that will contain your buffer.

    type
       big_byte_type = Packed array [0..63999] of byte;
       big_word_type = Packed array [0..31999] of word;

    var
       uPointer : ^big_byte_type;

    begin
    new(upointer);
    { to access it as an array of bytes }
    upointer^[1] := 0;
    { to access it as an array of words }
    big_word_type(upointer^)[2] := 3;
    end;

Chuck Todd
at Warp with Speed Pascal/2

Re:POINTERS POINTERS...


   You can use the MEM or MEMW command

   Example:    MyData := MemW[Seg(vaddrp):Ofs(vaddrp)];

Quote
Erik Lundh <may...@algonet.se> wrote:
>I got a problem here.. I have defined a pointer like this:

>var    vaddr            : word;
>       vaddrp           : pointer;

>begin
>  getmem(vaddrp,64000); vaddr:=seg(vaddrp^);

>[cut]

>now.. if I want a part of the pointer, HOW DO I DO? I thought it was
>like this vaddrp^whatever but it doesn't work! HELP ME AND I WOULD BE
>GREATFULL!

--

          ___                                              ___
          L_|_                                            _|_J
         ( -O>                                            <O- )
      ___//\J  __________________________________________  L/\\___
     //-,\    |                                          |    /,-\\
    || / \\___L   AVONTURE Christophe (c) AVC Software   J___// \ ||
  _ ''/\/ '---J    Christophe.Avont...@is.belgacom.be    L---' \/\'' _
 / \ //\\.    |__________________________________________|    .//\\ / \
|_/\'/  ||                                                    ||  \'/\_|
     '   ||_         "Make sure that, always!, you            _||   '
         |__)       reply to my private mail adress"         (__|

Delphi Super Page: http://sunsite.icm.edu.pl/archive/delphi/delphi
Delphi Super Site: http://sunsite.icm.edu.pl/~robert/delphi
Delphi Others:     http://www.coast.net/~jkeller
                   http://www.pobox.com/~bstowers/delphi

 "Postings are personnal, and don't reflect Belgacom's opinion"

Other Threads