• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1131
  • Last Modified:

Saving and Restoring DevEx view information via streams

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
ttheimer
Asked:
ttheimer
  • 2
1 Solution
 
Mechanic_KharkovCommented:
Maybe and of stream?

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

Open in new window

0
 
Mechanic_KharkovCommented:
*end of stream :-)
0
 
ttheimerAuthor Commented:
Spot on!  I added the line to reset the stream position and the save and restore worked as intended.  Thank you.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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