📄 enum_u1.~pas
字号:
unit Enum_U1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Buttons, ExtCtrls, ActiveX, ComObj;
type
TForm2 = class(TForm)
Panel1: TPanel;
sbut_Load: TSpeedButton;
tv_Enum: TTreeView;
sbar_Simple: TStatusBar;
odlg_DocFile: TOpenDialog;
procedure sbut_LoadClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ProcessFile( sFileName : WideString );
procedure EnumInStorage( Stor : IStorage; Node : TTreeNode );
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.EnumInStorage(Stor: IStorage; Node: TTreeNode);
var
Hr : HResult;
Enum : IEnumSTATSTG;
SubNode : TTreeNode;
StatStg : TStatStg;
SubStor : IStorage;
HrSubStor : HResult;
NumFetched : integer;
begin
{Start enumeration}
Hr := Stor.EnumElements( 0, nil, 0, Enum );
OleCheck( Hr );
repeat
{Get 1 STATSTG}
Hr := Enum.Next( 1, StatStg, @NumFetched );
{Was a STATSTG retrieved?}
if( Hr <> S_OK ) then
continue;
{What type of element was returned?}
case StatStg.dwType of
STGTY_STORAGE : {Name of IStream element}
begin
{Add node for the IStorage}
SubNode := tv_Enum.Items.AddChild( Node, StatStg.pwcsName );
{Open the sub-storage}
HrSubStor := Stor.OpenStorage( StatStg.pwcsName,
nil,
STGM_READWRITE or STGM_DIRECT or
STGM_SHARE_EXCLUSIVE,
nil,
0,
SubStor
);
{If the storage was not opened}
if( SUCCEEDED( HrSubStor ) ) then
begin
{Enum all elements in the sub-storage}
EnumInStorage( SubStor, SubNode );
end;
end;
STGTY_STREAM : {Name of IStream element}
begin
{Add node for the stream}
tv_Enum.Items.AddChild( Node, StatStg.pwcsName );
end;
end;
{Until an error occurs, or enum function indicates a stop}
until ( Hr <> S_OK );
end;
procedure TForm2.ProcessFile(sFileName: WideString);
var
Hr : HResult;
Root : IStorage;
begin
{Open storage}
Hr := StgOpenStorage( PWideChar(sFileName),
nil,
STGM_READWRITE or STGM_DIRECT or
STGM_SHARE_EXCLUSIVE,
nil,
0,
Root
);
{File opened?}
if( not SUCCEEDED( Hr ) ) then
begin
MessageBeep(-1);
ShowMessage( 'Cant open file - ' + sFileName );
Exit;
end;
{Add Root}
tv_Enum.Items.Add( nil, sFileName );
{Display name of open file}
sbar_Simple.SimpleText := sFileName;
{Start the enumeration}
EnumInStorage( Root, tv_Enum.Items[ 0 ] );
{Show all}
tv_Enum.FullExpand;
end;
procedure TForm2.sbut_LoadClick(Sender: TObject);
var
ws : WideString;
begin
{Select a DocFile to open}
if( not odlg_DocFile.Execute ) then
Exit;
{Remove old file info}
sbar_Simple.SimpleText := '';
tv_Enum.Items.Clear;
{Get UNICODE file name}
ws := odlg_DocFile.FileName;
{Check that this is a DocFile}
if( StgIsStorageFile( PWideChar(ws) ) <> S_OK ) then
begin
MessageBeep( MB_ICONEXCLAMATION );
ShowMessage( 'Not a doc file' );
Exit;
end;
{Load and parse}
ProcessFile( odlg_DocFile.FileName );
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -