Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!.POSTED!not-for-mail From: Marco van de Voort Newsgroups: comp.lang.pascal.delphi.misc Subject: Re: xpost (Sorry) Can someone show me the fix for this please? Date: Thu, 19 Jul 2012 19:45:05 +0000 (UTC) Organization: Stack Usenet News Service Lines: 30 Message-ID: References: NNTP-Posting-Host: toad.stack.nl Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: mud.stack.nl 1342727105 38015 2001:610:1108:5010::135 (19 Jul 2012 19:45:05 GMT) X-Complaints-To: abuse@stack.nl NNTP-Posting-Date: Thu, 19 Jul 2012 19:45:05 +0000 (UTC) User-Agent: slrn/0.9.9p1 (FreeBSD) Xref: csiph.com comp.lang.pascal.delphi.misc:373 On 2012-07-19, bok wrote: > > The line below of "S:=Reversestring(S)" causes a file full of "nul" to be written instead of S. How do I manipulate S and then correctly write the altered > string to n2.exe. An empty string might be NIL. Dereferencing NIL might cause an exception. > Thanks, > DBM >========================================================= > > procedure TForm1.Button1Click(Sender: TObject); > var > readit,writeit: TFileStream; > s: string; > x:integer; > begin > readit := TFileStream.Create('n1.exe', fmOpenread); > writeit := TFileStream.Create('n2.exe', fmCreate or fmOpenWrite); > try > SetLength(s,readit.Size); if length(s)>0 > readit.Read(PChar(s)^, Length(s)); > s:=reversestring(s); //<<<<<<-This line is incorrect > writeit.Write(PChar(s)^, Length(s)); > finally > readit.Free; > writeit.Free; > end; > end;