Board index » delphi » Delphi2 - pointer via pointer, possible??

Delphi2 - pointer via pointer, possible??

Hi there!

Me again and again :))

I have pointer P1 that points to variable A.. Then I have pointer P2 that
points to P1... How to point P1 to variable B, using only P2 ???
    I tried: P2:=@B but this only changes where P2 points...

    I did this using asm, but I wonder if there is 'pascal' solution..

----------
Actualy... what I need, is that some function gives me pointer to some
variable, and returns if succesfully... I did this:
function GetMyPointer(P2:pointer):boolean;

then I use it as:
 MyResultBoolean:=GetMyPointer(P1);

But in function GetMyPointer, I occur problem that I put before...

Any help will be highly appreciated!

--

------------------------------------------------------------------------
                             Matija Tomaskovic
               <<< Mataya software - company in progress >>>

 mtoma...@barok.foi.hr               Matija Tomaskovic, Matije Gupca 25
 mtom...@jagor.srce.hr                Jalkovec, 42000 Varazdin, Croatia
 http://barok.foi.hr/~mtomasko     voice/modem/fax: ++385 (0)42 261-617
------------------------------------------------------------------------

 

Re:Delphi2 - pointer via pointer, possible??


On Fri, 11 Apr 1997 11:02:01 +0200, mtoma...@barok.foi.hr (Matija

Quote
Tomaskovic) wrote:
>Hi there!

>Me again and again :))

>I have pointer P1 that points to variable A.. Then I have pointer P2 that
>points to P1... How to point P1 to variable B, using only P2 ???
>    I tried: P2:=@B but this only changes where P2 points...

>    I did this using asm, but I wonder if there is 'pascal' solution..

>----------
>Actualy... what I need, is that some function gives me pointer to some
>variable, and returns if succesfully... I did this:
>function GetMyPointer(P2:pointer):boolean;

>then I use it as:
> MyResultBoolean:=GetMyPointer(P1);

>But in function GetMyPointer, I occur problem that I put before...

>Any help will be highly appreciated!

What about :
P2^:=@B   //if the types are compatible

Tjarko

Re:Delphi2 - pointer via pointer, possible??


Hi Matija

Quote
> I have pointer P1 that points to variable A.. Then I have pointer P2 that
> points to P1... How to point P1 to variable B, using only P2 ???
>     I tried: P2:=@B but this only changes where P2 points...

>     I did this using asm, but I wonder if there is 'pascal' solution..

Yes it is possible in pascal, see following example;
var
  p1 : ^integer;
  p2 : ^pointer;
  A : integer;
  B : integer;
begin
  (* Just so we know whats being pointed to *)
  a:=1;
  b:=2;

  getmem(p1,sizeof(pointer));
  getmem(p2,sizeof(pointer));

  p1^ := a ;  
  p2 := @p1;  // p2 now points at what is stored in p1
  p2^:=@b  ;  // Change what p2 is pointing too, i.e. what is
              // stored in p1 to location of variable P
end;

If you step through this with watches on p1, p2, p1^, p2^ you will
see how it works a lot better

HTH
Allan

Re:Delphi2 - pointer via pointer, possible??


Quote
Matija Tomaskovic wrote:

> Hi there!

> Me again and again :))

> I have pointer P1 that points to variable A.. Then I have pointer P2 that
> points to P1... How to point P1 to variable B, using only P2 ???
>     I tried: P2:=@B but this only changes where P2 points...

>     I did this using asm, but I wonder if there is 'pascal' solution..

> ----------
> Actualy... what I need, is that some function gives me pointer to some
> variable, and returns if succesfully... I did this:
> function GetMyPointer(P2:pointer):boolean;

> then I use it as:
>  MyResultBoolean:=GetMyPointer(P1);

> But in function GetMyPointer, I occur problem that I put before...

> Any help will be highly appreciated!

var
  p1, p2 : POINTER;
  i      : INTEGER;

begin
  i := 1;
  p1 := @i;
  p2 := @p1;

  LONGINT(POINTER(p2^)^) := 2;

// Now, i = 2

Regards,

Erik.

--
Need a custom component? Late on a project? Could use an util?
DOS Device driver? A VxD? NT drivers or services?
Applications of any kind?
Low rates, fast delivery!

When responding to news postings, please CC a copy to my email address.
Thanks.
Erik Sperling Johansen <e...@info-pro.no>

Re:Delphi2 - pointer via pointer, possible??


Quote
Erik Sperling Johansen wrote:

> Matija Tomaskovic wrote:

> > Hi there!

> > Me again and again :))

> > I have pointer P1 that points to variable A.. Then I have pointer P2 that
> > points to P1... How to point P1 to variable B, using only P2 ???
> >     I tried: P2:=@B but this only changes where P2 points...

> >     I did this using asm, but I wonder if there is 'pascal' solution..

> > ----------
> > Actualy... what I need, is that some function gives me pointer to some
> > variable, and returns if succesfully... I did this:
> > function GetMyPointer(P2:pointer):boolean;

> > then I use it as:
> >  MyResultBoolean:=GetMyPointer(P1);

> > But in function GetMyPointer, I occur problem that I put before...

> > Any help will be highly appreciated!

> var
>   p1, p2 : POINTER;
>   i      : INTEGER;

> begin
>   i := 1;
>   p1 := @i;
>   p2 := @p1;

>   LONGINT(POINTER(p2^)^) := 2;

> // Now, i = 2

Hmmm... This wasn?t what you asked, was it?

try POINTER(p2^) := @B

Erik.

--
Need a custom component? Late on a project? Could use an util?
DOS Device driver? A VxD? NT drivers or services?
Applications of any kind?
Low rates, fast delivery!

When responding to news postings, please CC a copy to my email address.
Thanks.
Erik Sperling Johansen <e...@info-pro.no>

Re:Delphi2 - pointer via pointer, possible??


In article <9muki5.lm5...@firewall.foi.hr>,
  mtoma...@barok.foi.hr (Matija Tomaskovic) wrote:

Quote

> Hi there!

> Me again and again :))

> I have pointer P1 that points to variable A.. Then I have pointer P2 that
> points to P1... How to point P1 to variable B, using only P2 ???
>     I tried: P2:=@B but this only changes where P2 points...

>     I did this using asm, but I wonder if there is 'pascal' solution..

      IF what you want to do is EXACTLY what you say you want (???)
you could do that by saying

P2^:= @B;

David Ullrich

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

Other Threads