Go Premium for a chance to win a PS4. Enter to Win


Save and Load Streams to WPTOOLS

Posted on 2010-09-20
Medium Priority
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
  • 4
  • 3

Expert Comment

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

Accepted Solution

Geert Gruwez earned 1500 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 (http://www.toadworld.com/MYSQL/tabid/762/Default.aspx)
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

916 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