Article View: borland.public.cppbuilder.internet.web
Article #771Re: Getting TCppWebBrowser as Text From Stream
From: Remy Lebeau (TeamB)
Date: Thu, 09 Mar 2006 21:21
Date: Thu, 09 Mar 2006 21:21
43 lines
2589 bytes
2589 bytes
"caleb" <nos@pam.com> wrote in message
news:44103b71$1@newsgroups.borland.com...
> As I stated existing deja code was saving to file as always,
> I can view the file in notepad and it is as expected.
> But when I LoadFromFile the saved file into a TStringList
> and look at the TStringList->Text the page source is again
> truncated.
The only way the data can truncated is if there are embedded null characters
in the data. TStrings::LoadFromFile() calls TStrings::LoadFromStream(),
which calls TStrings::SetTextStr(). SetTextStr() treats the input data as a
null-terminated string, regardless of its actual length. If there is an
null character in the data, the data will be truncated.
> It is not a memory issue. I am not familiar with AnsisString
> to know why it truncates the page.
It is not an AnsiString problem. It is a TStrings problem.
TStrings::LoadFromFile() creates an AnsiString containing the full data from
the file, but TStrings::SetTextStr() does not fully parse the AnsiString
properly.
The answer to your truncating problem is simple - don't use TStringList to
load the data. Use a TFileStream or TMemoryStream to load the file data
directly into your AnsiString, ie:
#include <memory>
AnsiString Source;
std::auto_ptr<TFileStream> Stream(new TFileStream("your file.htm",
fmOpenRead | fmShareDenyWrite));
Source.SetLength(Stream->Size);
if( Soure.Length() > 0 )
Stream->Read(Source.data(), Soure.Length());
A better solution would be to not read the browser data into a file at all,
but into your AnsiString dirctly. You already have the code to do that.
Gambit
Technical Details
Message-ID:
<44109c32$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<440f9e16$1@newsgroups.borland.com> <440fe89f$1@newsgroups.borland.com> <44103b71$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,274260257bdc682e X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <440f9e16$1@newsgroups.borland.com> <440fe89f$1@newsgroups.borland.com> <44103b71$1@newsgroups.borland.com> Subject: Re: Getting TCppWebBrowser as Text From Stream Date: Thu, 9 Mar 2006 13:21:55 -0800 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <44109c32$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141939250 68.69.17.41 (9 Mar 2006 13:20:50 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail