Solved

Save and Load Streams to WPTOOLS

Posted on 2010-09-20
8
1,355 Views
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

Thanks
0
Comment
Question by:rcdcsjdc
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:briangochnauer
Comment Utility
Post the project for quickest response.
0
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
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 ?
0
 

Author Closing Comment

by:rcdcsjdc
Comment Utility
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

SO
  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');
  WP.Clear;
  WP.LoadFromStream(Strm,'WPTOOLS');

comes up with a blank Word Processor

BUT
  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');
  Strm.SaveToFile('P:\GetGeneralBlobstrm.dat');
  Strm.Clear;
  Strm.LoadFromFile('P:\GetGeneralBlobstrm.dat');
  WP.Clear;
  WP.LoadFromStream(Strm,'WPTOOLS');

works PERFECTLY.
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
0
 
LVL 5

Expert Comment

by:briangochnauer
Comment Utility
These statements are redundant; both return a stream; making the first one superfluous and a memory leak.
  Strm := TMemoryStream.Create;
  Strm := MySqlModule.GetGeneralBlob('HomePageBlob');
 
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:rcdcsjdc
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:briangochnauer
Comment Utility
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.
 
0
 

Author Comment

by:rcdcsjdc
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:briangochnauer
Comment Utility
Exactly.
Since it can not be free'd by the program that created it, it will stay on the heap forever.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now