Save and Load Streams to WPTOOLS

Posted on 2010-09-20
Last Modified: 2013-11-23
I have what seems to me a very simple requirement.

I have been using WPTOOLS for a number of years to create HTML web content..

The problem for me is that if you use this component to save a Document as HTML and then Reload for editing later, it often messes up ESPECIALLY with tables.

So I had another idea, If you save the data in 2 formats. HTML for the web content only, and WPTOOLS own format so that when you re-load it there is no loss of formatting that happens with the HTML only version

Since MY data is all stored on a MySQL database I thought that it would be simple to do the following

1. Save the WPTOOLS data to a TMemoryStream
2. Save the TMemoryStream as a BLOB in the MySQL using MYDAC
3. Load the BLOB back as a Memory Stream  using MYDAC
4. Load the Memory Stream back into WPTOOLS.

However No matter what options I try it simply doesnt work,
There does seem to always be data IN the MySQL BLOB field because it has a size of a few K, but when it comes to loading things back the WPTOOLS richedit is ALWAYS BLANK.

Rather than putting my clearly inadequate code on, maybe someone could suggest some fully working code

Question by:rcdcsjdc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 33719716
Post the project for quickest response.
LVL 37

Accepted Solution

Geert Gruwez earned 500 total points
ID: 33722879
when i run into a problem like this, this is what i do:

you have the document in both formats on your disk ?
using a tool like Toad (
i create a table and in a record add the files to the blobs
using the record editor of toad

then in delphi i created a second record and save the same content to the mysql database

in toad i then check if i have the same type of contents

if not, then obviously something went wrong

>WPTOOLS Data ???
Are you sure you can save/load that directly to the stream ?

Does it work if you first save the WPTools content to file and save the file to the database ?

Author Closing Comment

ID: 33726712
actually the thing that solved it for me was the saving of the stream to file at each step of the way.
It showed a strange anomoly in that EVERY version of the file was IDENTICAL down to the last byte when saved to a file.
BUT interestingly the issue was in the loading into WPTOOLS.
If you try to load the stream that comes directly from the blob back into WPTOOLS it is blank but if you load one from a saved file it is perfect

  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');

comes up with a blank Word Processor

  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');

This suggests that the format of the stream is somehow different when retrieved from a MySQL blob (at least using my version of MYDAC) than when retrieved from a file
Thanks to all who helped
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 33727706
These statements are redundant; both return a stream; making the first one superfluous and a memory leak.
  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');

Author Comment

ID: 33732315
Yes it is redundant, it was left in from all the earlier testing when things didn't work.
I rarely get the time to tune and optimise, generally just getting things to work properly without error seems to be the norm.
What interests me is the issue of why it would be a memory leak.
I admit to knowing ABSOLUTELY NOTHING about memory leaks, what causes them, what should be done to avoid them etc.
I would have automatically assumed that since the Strm variable is used continually throughout the procedure then regardless of how you use it, it would be naturally disposed of and cleaned up at the end of it.
Maybe you could enlighten a little further.

Expert Comment

ID: 33735903
Not sure I can make it clear without pictures :) , but I'll try
      1. Assigns strm to a stream created on the memory heap

 Strm := TMemoryStream.Create;      
 Strm := MySqlModule.GetGeneralBlob('HomePageBlob');  
   2. Strm is reassigned to the return value of a function
             The original stream created on the heap is not destroyed;
             since there is no variable in your program that has reference to it.          
        If you were to call FreeAndNil(Strm) it would free the stream created in GetGeneralBlob function not the one created by TMemoryStream.Create;
Hope that is clear.

Author Comment

ID: 33736274
Thank You,
As far as I understand it what you are saying is that it does not alter the value of the stream or add to in in any way it simply re-assigns where Strm is pointed, thus losing contact with the original location which is now not addressable in any way.

Expert Comment

ID: 33736327
Since it can not be free'd by the program that created it, it will stay on the heap forever.

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: Connect to running MS Outlook 4 209
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 52
Syntax Error 2 115
JavaFX TableView not displaying correctly 3 161
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question