The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,308 other followers

Until someone writes proper string visualisers for the Delphi debugger…

Posted by jpluimers on 2017/10/31

A few tricks to write long strings to files when the Delphi debugger cuts them off (just because they like using 4k buffers internally);

  • TStringStream.Create(lRequestMessage).SaveToFile('c:\temp\temp.txt')
  • TIniFile.Create('c:\a.txt').WriteString('a','a',BigStringVar)
  • TFileStream.Create('c:\a.txt', fmCreate or fmShareDenyNone).WriteBuffer(Pointer(TEncoding.UTF8.GetBytes(BigStringVar))^,Length(TEncoding.UTF8.GetBytes(BigStringVar)))

They all work form the debug inspector, but they do leak memory. See comments below.

Via:

–jeroen

PS: Uwe Schuster on G+ and Twitter:

I am not sure if the buffer is not a little bit bigger, but still to small in recent versions. To quote myself “Cannot say it often enough – do use ReadProcessMemory for your visualizer” twitter.com – Uwe Schuster on Twitter and just build a simple visualizer.

 

6 Responses to “Until someone writes proper string visualisers for the Delphi debugger…”

  1. Remy said

    All three suggested workarounds are leaking memory/resources because they are not destroying the temp objects they create. They need to be wrapped in a try/finally. And in the case of the TFileStream.WriteBuffer() suggestion, calling TEncoding.GetBytes() twice for a long string is very inefficient and memory wasteful. Cache the result to a variable first. Or use TStreamWriter.Write(String) instead.

    • Remy said

      Also, the TStringStream and TIniFile approaches are not encoding the text to UTF-8, so they are subject to potential data loss for non-ASCII characters. At least the TFileStream approach (better TStreamWriter) takes UTF-8 into account.

    • jpluimers said

      I know. But they all work from the debug inspector. I’ll add a warning.

  2. Geza said

    TFile.WriteAllText(aPath, aContents)

  3. bascyBas said

    Another easy way is to copy it to the clipboard: write a small procedure that doesnt not much more then clipboard.astext := text and you can use that in the evaluate/modify window

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: