Home > Back-end >  How to use Delphi to modify the properties of doc file
How to use Delphi to modify the properties of doc file

Time:09-26

The front an article "Delphi implementation by file attributes to find the file", which give function can use Delphi get attributes of the file,
Who can help me write, modify the functions?
http://wenku.baidu.com/link? Url=_Y2JDM7ke6UiVtMPBKCUzDWBibhw2JJGHPBNl4g9VuB6aoZmWqKph4PqQ10XlMVQateGtVmd22LucJkkKkZNPz0MhapGgacuRrVUtf1rCEC this is "Delphi implementation according to the file attributes to find the" library version of

CodePudding user response:

//to read the code attribute
The unit PropertySet;

Interface

USES Windows, SysUtils ComObj, ActiveX;

Type
TPropertySet=class
Private
FFileName: WideString;
FActive: Boolean;
FPropertySetStorage: IPropertySetStorage;
FPropertyStorage: IPropertyStorage;
FStorage: IStorage;
FStreamGUID: TGUID;

Procedure SetActive (const Value: Boolean);
Procedure SetFileName (const Value: WideString);
Procedure SetStreamGUID (const Value: TGUID);
Protected
Procedure InternalOpen; The dynamic;
Procedure InternalClose; The dynamic;
Public
The constructor Create;
The destructor Destroy; Override.
Procedure Open;
Procedure Close;
The function GetPropertyByName (APropertyName: WideString) : TPropVariant;
The function GetPropertyByID (APropertyID: Integer) : TPropVariant;

Cable property Active: Boolean read FActive write SetActive;
The property FileName: WideString read FFileName write SetFileName;
The property StreamGUID: TGUID read FStreamGUID write SetStreamGUID;
The end;

Const
FMTID_SummaryInformation: TGUID='{ff9 F29F85E0-4-1068 - AB91-08002 b27b3d9}';
FMTID_DocumentSummaryInformation: TGUID='{e9c D5CDD502-2-101 - b - 9397-08002 b2cf9ae}';
FMTID_UserDefinedProperties: TGUID='{e9c D5CDD505-2-101 - b - 9397-08002 b2cf9ae}';
IID_IPropertySetStorage: TGUID='{0000013} a - 0000-0000 - C000-000000000046';

Implementation
Type
TPropSpecArray=array [0.. 1000] of TPropSpec;
PPropSpecArray=^ TPropSpecArray;
TPropVariantArray=array [0.. 1000] of TPropVariant;
PPropVariantArray=^ TPropVariantArray;

TagSTGOPTIONS=record
UsVersion: ShortInt;
Reserved: Short;
UlSectorSize: LongInt;
PwcsTemplateFile: PWideChar;
The end;

STGOPTIONS=^ tagSTGOPTIONS;

Const
STGFMT_STORAGE=0;
STGFMT_FILE=3;
STGFMT_ANY=4;
STGFMT_DOCFILE=5;

The function StgOpenStorageEx (const pwcsName: POleStr; GrfMode: Longint;
STGFMT: DWORD; GrfAttrs: DWORD; PStgOptions: STGOPTIONS; Reserved2: Pointer;
Riid: PGUID; The out ppObjectOpen: IStorage) : HResult; Stdcall;
External 'ole32. DLL';

The constructor TPropertySet. Create;
The begin
Inherited;
FStreamGUID:=FMTID_SummaryInformation;
The end;

Destructor TPropertySet. Destroy;
The begin
The Close;
The end;

Procedure TPropertySet. Open;
The begin
Active:=True;
The end;

Procedure TPropertySet. Close;
The begin
Active:=False;
The end;

The function TPropertySet. GetPropertyByName (APropertyName: WideString) : TPropVariant;
Var
Ps: PPropSpecArray;
Pv: PPropVariantArray;
The begin
Ps:=nil;
Pv:=nil;
Try
GetMem (ps, sizeof (TPropSpec));
GetMem (pv, sizeof (TPropVariant));
Ps [0]. UlKind:=PRSPEC_LPWSTR;
Ps [0]. LPWSTR:=PWideChar (APropertyName);
OleCheck (FPropertyStorage ReadMultiple (1, @ ps [0], @ pv [0]));
The Result: pv=[0];
The finally
If ps & lt;> Nil then
FreeMem (ps);
If pv & lt;> Nil then
FreeMem (pv);
The end;

The end;

Function TPropertySet. GetPropertyByID (APropertyID: Integer) : TPropVariant;
Var
Ps: PPropSpecArray;
Pv: PPropVariantArray;
The begin
Ps:=nil;
Pv:=nil;
Try
GetMem (ps, sizeof (TPropSpec));
GetMem (pv, sizeof (TPropVariant));
Ps [0]. UlKind:=PRSPEC_PROPID;
Ps [0]. Propid:=APropertyID;
OleCheck (FPropertyStorage ReadMultiple (1, @ ps [0], @ pv [0]));
The Result: pv=[0];
The finally
If ps & lt;> Nil then
FreeMem (ps);
If pv & lt; & gt; Nil then
FreeMem (pv);
The end;
The end;

Procedure TPropertySet. InternalOpen;
The begin
If FFileName="' then
Raise the Exception. Create (' file name must be set! ');
OleCheck (StgOpenStorageEx (PWChar (FFileName), STGM_READ or STGM_SHARE_DENY_WRITE,
STGFMT_ANY, 0, nil nil, @ IID_IPropertySetStorage, FStorage));
FPropertySetStorage:=FStorage as IPropertySetStorage;
OleCheck (FPropertySetStorage. Open (FStreamGUID STGM_READ or STGM_SHARE_EXCLUSIVE,
FPropertyStorage));
The end;

Procedure TPropertySet. InternalClose;
The begin
FPropertyStorage:=nil;
FPropertySetStorage:=nil;
FStorage:=nil;
The end;

Procedure TPropertySet. SetActive (const Value: Boolean);
The begin
Cable if FActive & lt;> The Value then
The begin
If the Value then
InternalOpen
The else
InternalClose;
FActive:=Value;
The end;
The end;

Procedure TPropertySet. SetFileName (const Value: WideString);
The begin
If FFileName & lt;> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related