RE: Converting Pchar to Char array
Stephen Wood <[email protected]> Wed, 20 Aug 2003 08:03:58 +0200
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <74D67F1862B5D711A9CA00B0D0D1F4C981AC00@dhexchange3.discoveryhealth.co.za> |
If your PChar is 1025 bytes (exactly the size of your array), and your loop
is looping 1024 times, then you will not have the 0 terminator at the end of
your buffer....
Try...
var
mx : PChar;
mnx : Array[0..1024] of Char;
mbn : Integer;
Begin
for mnb := 0 to 1023 do
mnx[I] := mx[I];
mnx[1024] := #0;
or...
var
mx : PChar;
mnx : Array[0..1024] of Char;
Begin
FillChar(mnx,SizeOf(mnx),0);
Move(mx^,mnx,Min(StrLen(mx),SizeOf(mnx)));
The FillChar will initialize your buffer, and the Move will move your PChar
into the buffer. The use of the Min function (found in the Math unit) will
prevent buffer overrun.....
HTH
-----Original Message-----
From: Dennis Morgan [mailto:[email protected]]
Sent: Wednesday 20 August 2003 04:04
To: [email protected]
Subject: [Delphi] Converting Pchar to Char array
Hi,
This may be a really stupid question...I know in C++ how to do it..
I need to track down a safe way to convert a Pchar string to a Char
array..
So I can add the nil character at the end to allow me to convert it to a
string.
And also thanks to Joe, who directed me to the ICS Suite, it solved a
few problems...
This is a snipet of the code:
var
mx : PChar;
mnx : Array[0..1024] of Char;
mbn : Integer;
Begin
for mnb := 0 to 1023 do
mnx[I] := mx[I];
My luck its something really simple.. But then I have been looking at
the socket related code all night trying to
track a bug down...
Regards.
Dennis
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003
Delphi VCL Top Sites!
http://www.sandbrooksoftware.com/TS/TS2/Components.shtml
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM
---------------------------------------------------------------------~->
Delphi VCL Top Sites!
http://www.sandbrooksoftware.com/TS/TS2/Components.shtml
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/