Board index » delphi » !!Help on doing string functions on a pointer

!!Help on doing string functions on a pointer

I don't work with pointers very much, so I'm a little confused.

I'm reading a file in chunks, and I want to be able search in the chunks
for the data and extract it.  

So....how do I do this.....Help!!

var
  CopyBuffer:Pointer;
  BiteSize:LongInt;
  WorkString;string;

begin
BiteSize:8192;

...some code to read the file into the buffer

  //CopyBuffer now points to a buffer containing 8192 bytes
  //can I do this?
  WorkString:=CopyBuffer;

// I'm searching for the position of a string in the buffer
if Pos('AA',WorkString)>0 then
....

Or is there an easier way to just use the pointer somehow?

Thanks!!

 

Re:!!Help on doing string functions on a pointer


Quote
Mike Philbrick wrote:

> I don't work with pointers very much, so I'm a little confused.

> I'm reading a file in chunks, and I want to be able search in the chunks
> for the data and extract it.

> So....how do I do this.....Help!!

> var
>   CopyBuffer:Pointer;
>   BiteSize:LongInt;
>   WorkString;string;

> begin
> BiteSize:8192;

> ...some code to read the file into the buffer

>   //CopyBuffer now points to a buffer containing 8192 bytes
>   //can I do this?
>   WorkString:=CopyBuffer;

> // I'm searching for the position of a string in the buffer
> if Pos('AA',WorkString)>0 then
> ....

> Or is there an easier way to just use the pointer somehow?

> Thanks!!

Simply read your chunk of data to a memory block that has a size
of one byte more than the chunk of data. Make sure that last
byte contains a null char (#0 or Char(000)). Then you can
use StrPos to get a pointer to the located data. Of course, the data
itself cannot contain a null character.

Joe
--
Joe C. Hecht
(Borland Delphi Developer Support)
Join the Delphi Online Discussion Forum at
http://www.borland.com/techsupport/delphi/

Other Threads