Board index » delphi » Pointer To Pointer...ACK!

Pointer To Pointer...ACK!

Hello All,

I'm messing around with Delphi and am having trouble remembering my syntax
for pointer to pointer etc...I want to create a pointer to an array of
pointers to PChar strings.

I manage to gracefully stomp all over memory and hang my machine no matter
what syntax I use.

Any help that would save me the trouble of rebooting my machine every 5
minutes would help.

Thanks

Andy Sprecher

 

Re:Pointer To Pointer...ACK!


Quote
Andrew Sprecher wrote:

> Hello All,

> I'm messing around with Delphi and am having trouble remembering my syntax
> for pointer to pointer etc...I want to create a pointer to an array of
> pointers to PChar strings.

> I manage to gracefully stomp all over memory and hang my machine no matter
> what syntax I use.

> Any help that would save me the trouble of rebooting my machine every 5
> minutes would help.

> Thanks

> Andy Sprecher

type
  TPCharArray = array[0..2] of PChar;
  PPCharArray = ^TPCharArray;

procedure TForm1.Button1Click(Sender: TObject);
var
  p : PPCharArray;
begin
  GetMem(p, sizeof(TPCharArray));
  GetMem(p^[0], 32);
  GetMem(p^[1], 32);
  GetMem(p^[2], 32);
  StrCopy(p^[0], 'Test1');
  StrCopy(p^[1], 'Test2');
  StrCopy(p^[2], 'Test2');

  ShowMessage(p^[1]);

  FreeMem(p^[0], 32);
  FreeMem(p^[1], 32);
  FreeMem(p^[2], 32);
  FreeMem(p, sizeof(TPCharArray));

end;

--
Joe C. Hecht
Borland Delphi Developer Support Group
Technical Documents and Online Forums are available at
http://www.borland.com

Re:Pointer To Pointer...ACK!


Quote
Andrew Sprecher wrote:
> Hello All,
> I'm messing around with Delphi and am having trouble remembering my syntax
> for pointer to pointer etc...I want to create a pointer to an array of
> pointers to PChar strings.
> I manage to gracefully stomp all over memory and hang my machine no matter
> what syntax I use.
> Any help that would save me the trouble of rebooting my machine every 5
> minutes would help.
> Thanks

type
   PcharPointer = ^PCHar;

var
   s : pChar;
   p : PCharPointer;
begin
   p := @s;

now
  p^=s
  p^^=s[0]

Hope this helps,
Jochen

Re:Pointer To Pointer...ACK!


Try the following thing:

type
  PPCharArray=^TPCharArray;
  TPCharArray=array[0..{Your number}] of PChar;
...
var
  PCharArray: PPcharArray;
...
  New(PCharArray); {for allocation the whole pointer structure, OR}
  GetMem(PCharArray,SizeOf(PChar)*Elements); {allocate only a part}
...
  ..PCharArray^[Element].. {to access the Pointer Array OR}
  ..PCharArray[Element].. {should also work}
...
  Dispose(PCharArray); {if you've used Ner to allocated OR}
  FreeMem(PCharArray,SizeOf(PChar)*Elements); {after GetMem}

I think this should work. But why aren't you just using a TList which is
much more flexible?

Arsne von Wyss
avonw...@datacomm.ch

Andrew Sprecher <and...@salesoft.com> schrieb im Beitrag
<01bc28ca$032432a0$0f3d3289@andspr4>...

Quote
> I'm messing around with Delphi and am having trouble remembering my
syntax
> for pointer to pointer etc...I want to create a pointer to an array of
> pointers to PChar strings.

> I manage to gracefully stomp all over memory and hang my machine no
matter
> what syntax I use.

> Any help that would save me the trouble of rebooting my machine every 5
> minutes would help.

> Thanks

> Andy Sprecher

Other Threads