Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1432
  • Last Modified:

Save and Load Streams to WPTOOLS

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
rcdcsjdc
Asked:
rcdcsjdc
  • 4
  • 3
1 Solution
 
briangochnauerCommented:
Post the project for quickest response.
0
 
Geert GOracle dbaCommented:
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
 
rcdcsjdcAuthor Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
briangochnauerCommented:
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
 
rcdcsjdcAuthor Commented:
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
 
briangochnauerCommented:
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
 
rcdcsjdcAuthor Commented:
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
 
briangochnauerCommented:
Exactly.
Since it can not be free'd by the program that created it, it will stay on the heap forever.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now