Board index » delphi » Dynamic length of PChar's, Pos() searching inside PChar

Dynamic length of PChar's, Pos() searching inside PChar

Dynamic length of PChar's, Pos() searching inside PChar

Procedure Speedbutton1.click(Sender: TOjbect)
var MyPCar: PChar
begin
   PChar:='hi there its a test of 36 characters'#0;
   speedbutton1.caption:='Length is:'+ inttostr(sizeof(PChar));
end;

The results shows a length of 4!. What is this? I wish to know how
long (how many characters) the text is that is stored in the PChar.

Also, I see no Pos() function for PChar's in 16-bit. I wish to search
and replace a substring within a PChar.

Who knows how to do this?

Email me, I reply. Com...@Lottery.powernet.co.uk
Matthew       NB SEE BELOW!

N.B.: To email me, please send your message to this email address:  

Com...@Lottery.powernet.co.uk

That is my correct address. I do not enter my address in the automatic
header of the newsgroup. This helps avoid junk-email from
address-gathering robots.

 

Re:Dynamic length of PChar's, Pos() searching inside PChar


On Sun, 01 Feb 1998 16:20:24 GMT, in comp.lang.pascal.delphi.misc

Quote
PleaseSeeAddr...@TheBottom.OfMyMessage.co.uk  (Matthew) wrote:
>Dynamic length of PChar's, Pos() searching inside PChar

>Procedure Speedbutton1.click(Sender: TOjbect)
>var MyPCar: PChar
>begin
>   PChar:='hi there its a test of 36 characters'#0;
>   speedbutton1.caption:='Length is:'+ inttostr(sizeof(PChar));
>end;

I assume you meant to type "MyPCar" in the last two uses of PChar.

Quote
>The results shows a length of 4!. What is this? I wish to know how
>long (how many characters) the text is that is stored in the PChar.

The reason is that MyPCar is a pointer, and in Delphi, pointers are 4
bytes long.  You want to find out how long is the string that it
points to.  Use StrLen for that.

Quote
>Also, I see no Pos() function for PChar's in 16-bit. I wish to search
>and replace a substring within a PChar.

I think StrPos does what you want.

Duncan Murdoch

Quote
P.S.:  You wrote:
>N.B.: To email me, please send your message to this email address:    
> ...
>That is my correct address. I do not enter my address in the automatic
>header of the newsgroup. This helps avoid junk-email from
>address-gathering robots.

Actually, all that it does is to inconvenience people trying to
respond to you.  The robots can gather your address from the body just
as well as from the headers.  If you want to try to foil them, you
should get a new email address (the one you used has already been
gathered), and then never include it anywhere in any of your messages.

Re:Dynamic length of PChar's, Pos() searching inside PChar


In article <34d495e...@news.power.net.uk>,

Quote
PleaseSeeAddr...@TheBottom.OfMyMessage.co.uk  (Matthew) writes:
>var MyPCar: PChar
>begin
>   PChar:='hi there its a test of 36 characters'#0;
>   speedbutton1.caption:='Length is:'+ inttostr(sizeof(PChar));
>end;

>The results shows a length of 4!. What is this? I wish to know how
>long (how many characters) the text is that is stored in the PChar.

>Also, I see no Pos() function for PChar's in 16-bit. I wish to search
>and replace a substring within a PChar.

SizeOf() gives you the size of the _object_ not its dimension, and the object
size of a  PChar is the 4 bytes the pointer to a PChar takes.

What you want is StrLen() - see "String-Handling Routines (null-terminated)" in
the help file.

You'll also find StrPos() there.

Alan Lloyd
alangll...@aol.com

Re:Dynamic length of PChar's, Pos() searching inside PChar


Matthew schrieb in Nachricht <34d495e...@news.power.net.uk>...

Quote
>Dynamic length of PChar's, Pos() searching inside PChar

>Procedure Speedbutton1.click(Sender: TOjbect)
>var MyPCar: PChar
>begin
>   PChar:='hi there its a test of 36 characters'#0;
>   speedbutton1.caption:='Length is:'+ inttostr(sizeof(PChar));
>end;

>The results shows a length of 4!. What is this? I wish to know how
>long (how many characters) the text is that is stored in the PChar.

>Also, I see no Pos() function for PChar's in 16-bit. I wish to search
>and replace a substring within a PChar.

PChar is a pointer to a char. As Pointers are 4 bytes big, the result
is 4. The length of the string is:
StrLen(MyPChar). The Pos() function is for Delphi Strings, not for the
ASCII-Zero delimited type of strings, like C and Windows use. For
PChars (which normally point to ASCIIZ strings), you can use
StrPos(MyPChar, 'there').

Rudy Velthuis

Other Threads