Link to home
Start Free TrialLog in
Avatar of WBread
WBreadFlag for United States of America

asked on

Load a TOleContainer from a stream which contains a file image, without using CreateObjectFromFile

Hi,
I have a database which contains blobs loaded from file of various MS doc types such as Word and Excel.  I'm trying to load these into a TOleContainer in much the same way that CreateObjectFromFile() works, however, without having to write the contents out to disk, etc.  I've tried a number of combinations to no avail.  Below is a code snippet which may at least help in conveying what I am trying to accomplish.

Any help would be greatly appreciated!

...
      try
        Stream:=TMemoryStream.Create; {Creation memory stream and saving content from database}
        TBlobField(FDataLink.Field).SaveToStream(Stream);
        Stream.Seek(0,soFromBeginning);
        S := GetAssociatedClassname(ExtractFileExt(aOriginalFileName));  // Returns, for example, "Excel.Sheet.8" or "Word.Document.8"
        CreateObject(S, False);
        // LoadFromStream(Stream);  // doesn't work!!!!  ...Invalid Stream format
        if Assigned(Stream) then
          begin
            Stream.Free;
            Stream:=nil;
          end;
      except
        on E:exception do begin
          if Assigned(Stream) then Stream.Free;
          Raise;
        end;
      end;
...
ASKER CERTIFIED SOLUTION
Avatar of Jacco
Jacco
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WBread

ASKER

Hi Jacco,
This works great.  Thanks!!

I'm still trying to figured out how to make the document show up in the "viewing" mode, i.e. visible but without the toolbars/menus, that I initially see using CreateObjectFromFile.  If you happen to know this, I'd be glad to see it :)

Either way, this answer is complete and very welcome.

Thanks again
-Todd
I have tried getting that result but was not able to find it. I added the GetVerb(...) to have something similar...

Regards Jacco