?
Solved

Saving and Restoring DevEx view information via streams

Posted on 2009-04-07
3
Medium Priority
?
1,108 Views
Last Modified: 2013-11-23
I have two procedures, one of which is intended to write grid view information to a database field and the other is to read and use this information to restore the view.  Code is below.  I thought the procs were working with early testing but now I am wondering if that was a hallucination!?  I'm hoping someone can spot my problem.
 - I created similar procs where the information is stored to and restored from the registry and those work as expected
 - I can see the data being written and re-written to the database.
 - I have stepped through the program to verify that each of the commands are executing.
procedure TfrmMain.SaveShopGridsToDB;
var
  Stream: TMemoryStream;
  BS: TAdsBlobStream;
begin
  Stream := TMemoryStream.Create;
  try
    gtvShop.StoreToStream(Stream, [], '');
    dtm.tblCases.Edit;
    BS := TAdsBlobStream(dtm.tblCases.CreateBlobStream(
                       dtm.tblCases.FieldByName('CsShopGrid1'), bmWrite));
    try
      BS.CopyFrom(Stream, 0);
    finally
      BS.Free;
      dtm.tblCases.Post;
    end;
  finally
    Stream.Free;
  end;
end;
 
procedure TfrmMain.RestoreShopGridsFromDB;
var
  Stream: TMemoryStream;
  BS: TAdsBlobStream;
begin
  if dtm.tblCases.FieldByName('CsShopGrid1').IsNull then Exit;
  Stream := TMemoryStream.Create;
  try
    BS := TAdsBlobStream(dtm.tblCases.CreateBlobStream(
                       dtm.tblCases.FieldByName('CsShopGrid1'), bmRead)); 
    try
      Stream.CopyFrom(BS, 0);
      gtvShop.RestoreFromStream(Stream, True, False, [], '');
    finally
      BS.Free;
    end;
  finally
   Stream.Free;
  end;
end;

Open in new window

0
Comment
Question by:ttheimer
[X]
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
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 24093363
Maybe and of stream?

      Stream.CopyFrom(BS, 0);
      Stream.Position := 0;
      gtvShop.RestoreFromStream(Stream, True, False, [], '');

Open in new window

0
 
LVL 5

Accepted Solution

by:
Mechanic_Kharkov earned 2000 total points
ID: 24093367
*end of stream :-)
0
 

Author Closing Comment

by:ttheimer
ID: 31567829
Spot on!  I added the line to reset the stream position and the save and restore worked as intended.  Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 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