POINTERS POINTERS... 
Author Message
 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!



Wed, 18 Jun 1902 08:00:00 GMT  
 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!

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


Wed, 18 Jun 1902 08:00:00 GMT  
 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!

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



Wed, 18 Jun 1902 08:00:00 GMT  
 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!

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                      | _,-""-_,-""-_,-""-_,-""-_,-""-_,-" |




Wed, 18 Jun 1902 08:00:00 GMT  
 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.



Wed, 18 Jun 1902 08:00:00 GMT  
 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!

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



Wed, 18 Jun 1902 08:00:00 GMT  
 POINTERS POINTERS...

   You can use the MEM or MEMW command

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

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!

--

          ___                                              ___
          L_|_                                            _|_J
         ( -O>                                            <O- )
      ___//\J  __________________________________________  L/\\___
     //-,\    |                                          |    /,-\\
    || / \\___L   AVONTURE Christophe (c) AVC Software   J___// \ ||

 / \ //\\.    |__________________________________________|    .//\\ / \
|_/\'/  ||                                                    ||  \'/\_|
     '   ||_         "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"



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. pointers, pointers, pointers...

2. Pointers Pointers Pointers

3. Pointers to pointers

4. Beginner needs some pointers with 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