Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2007 Jan : How do you set the Title and Author values?

www.cryer.info
Managed Newsgroup Archive

How do you set the Title and Author values?

Subject:How do you set the Title and Author values?
Posted by:"Mark Patterson" (noe_zp..@stopbots.org)
Date:Thu, 25 Jan 2007 16:17:24

Hi,

We want to set the Title value of a file to make it correspond to the
Subject of an email, and similarly we want to set the Author property of
the file. I have been using some code that does it, but when I set the
Author, the Title vanishes from explorer, and vice versa.

Here's the code we're using so far:

procedure SetFileProperty(const FileName, value: string; const FmtID:
TGUID; PropID: integer);
var
   wFilename:   array[0..255] of WideChar;
   wValue:      array[0..255] of WideChar;
   stg:         IStorage;
   PropSetStg:  IPropertySetStorage;
   PropStg:     IPropertyStorage;
   PropSpec:    TPropSpec;    // record
   PropVariant: TPropVariant; // record
begin
   OleCheck(StgOpenStorage(StringToWideChar(FileName, wFilename,
Length(wFilename)), nil,
               STGM_SHARE_EXCLUSIVE or STGM_READWRITE, nil, 0, stg));
   PropSetStg := Stg as IPropertySetStorage;
   OleCheck(PropSetStg.Create(FmtID, FmtID, PROPSETFLAG_DEFAULT,
               STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
PropStg));
   PropSpec.ulKind := PRSPEC_PROPID;
   PropSpec.propid := PropID;
   PropVariant.vt := VT_LPWSTR;
   PropVariant.pwszVal := StringToWideChar(value, wValue, Length(wValue));
   OleCheck(PropStg.WriteMultiple(1, @PropSpec, @PropVariant, 2));
   PropStg.Commit(STGC_DEFAULT);
end;// SetFileProperty

TIA,

--
Mark Patterson
www.piedsoftware.com

Replies:

www.cryer.info
Managed Newsgroup Archive