
procedure TMainForm.Outline1DblClick(Sender: TObject);
var
  pszName: PChar;
  pIStorage: IStorage;
  pIStream: IStream;
  pMyStatStg: TMyStatStg;
  aOffset, dummyLargeint: Comp;
begin
  if Outline1.SelectedItem > 0 then begin
    pMyStatStg := TMyStatStg(m_lstIStorage.Items[Outline1.SelectedItem-1]);
    StatusBar.Caption := 'Selected Item: ' + StrPas(pMyStatStg.pszName);

    { Now try and open the stream for this node, but first close existing stream }
    if m_pStream <> nil then
      m_pStream.Release;

    if pMyStatStg.dwType = Longint(STGTY_STREAM) then begin
      pIStorage := pMyStatStg.pIStorage;
      pszName := pMyStatStg.pszName;

      { If there was already a stream open, release it first }
      if SUCCEEDEDHR(pIStorage.OpenStream(pszName, nil, STGM_READ
        or STGM_SHARE_EXCLUSIVE, 0, pIStream)) then begin

        { Setup the DrawGrid to Display this Stream }
        m_dwStreamSize := GetLowPart(pMyStatStg.cbSize);  { set the stream size variable }
        m_pStream := pIStream;                        { save the interface pointer }
        Drawgrid1.RowCount := m_dwStreamSize div 16;  { set the extent of the DrawGrid }
        Drawgrid1.Visible := True;

        { Seek to beginning of file }
        aOffset := 0;
        m_pStream.Seek(aOffset, Longint(STREAM_SEEK_SET), dummyLargeint);
      end;
    end
    else
      DrawGrid1.Visible := False;       { Hide Grid if not a Stream Object }
  end;
end;
Figure 10: Opening a Stream

