RE: Converting Pchar to Char array
Stephen Wood <[email protected]> Wed, 20 Aug 2003 08:08:36 +0200
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <74D67F1862B5D711A9CA00B0D0D1F4C981AC01@dhexchange3.discoveryhealth.co.za> |
Oh yes...the other method I showed you, would also not cater for the 0 terminator. To do that...use the following line Move(mx^,mnx,Min(StrLen(mx),SizeOf(mnx) - 1)); HTH -----Original Message----- From: Stephen Wood Sent: Wednesday 20 August 2003 08:04 To: '[email protected]' Subject: RE: [Delphi] Converting Pchar to Char array 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..... [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/