Board index » delphi » passing pointers to procedures

passing pointers to procedures

i'm trying to pass an array of pointers to a procedure, or just call the
procedure and have it do it's operations on the records. the pointers
point to records that have an element that i need to perform a computation
on. i want to try to avoid putting a loop in my main program that calls
the procedure x number of times.

thanks

i'm using tpw1.5

 

Re:passing pointers to procedures


Quote
bart...@aol.com (Barthie) wrote:

> i'm trying to pass an array of pointers to a procedure, or just call the
> procedure and have it do it's operations on the records. the pointers
> point to records that have an element that i need to perform a computation
> on. i want to try to avoid putting a loop in my main program that calls
> the procedure x number of times.

> thanks

> i'm using tpw1.5

Hope this example helps......

uses WinCrt;
Type
  PPtrArray = ^TPtrArray;
  TPtrArray = array[0..2] of Pointer;

Procedure HandlePtrArray(P: PPtrArray; NumPtrs: integer);
VAR
  Loop: integer;
  APtr : Pointer;
  aByte: byte;
begin
  for Loop := 0 to NumPtrs - 1 do
  begin
    APtr := P^[Loop];
    aByte := Byte(APtr^);
    writeln(aByte);
  end;
end;

VAR
  TheArray: TPtrArray;
  Byte0, Byte1, Byte2: Byte;
begin
  Byte0 := 10;
  Byte1 := 150;
  Byte2 := 255;
  TheArray[0] := @Byte0;
  TheArray[1] := @Byte1;
  TheArray[2] := @Byte2;
  HandlePtrArray(@TheArray, 3);
end.  

Have fun
James :-)

Re:passing pointers to procedures


Quote
In article <3tgp0l$...@newsbf02.news.aol.com> bart...@aol.com (Barthie) writes:
>From: bart...@aol.com (Barthie)
>Subject: passing pointers to procedures
>Date: 6 Jul 1995 09:38:29 -0400
>i'm trying to pass an array of pointers to a procedure, or just call the
>procedure and have it do it's operations on the records. the pointers
>point to records that have an element that i need to perform a computation
>on. i want to try to avoid putting a loop in my main program that calls
>the procedure x number of times.
>thanks
>i'm using tpw1.5

Why not just pass a pointer to your array of pointers like:
  someprocedure(@PtrArray);

Claude.

Other Threads