while Enum.Next(1, sps[0], @Fetched) = S_OK do begin
Prop := GetPropertyByID(sps[0].propid);
DoEnumProperty(sps[0].lpwstrName, sps[0].propid, Prop);
end;
finally
if ps <> nil then
FreeMem(ps);
if pv <> nil then
FreeMem(pv);
if sps <> nil then
FreeMem(sps);
end;
end;
function TPropertySet.GetPropertyByID(APropertyID: Integer): TPropVariant;
var
ps: PPropSpecArray;
pv: PPropVariantArray;
begin
ps := nil;
pv := nil;
try
GetMem(ps, sizeof(TPropSpec));
GetMem(pv, sizeof(TPropVariant));
OleCheck(FPropertyStorage.ReadMultiple(1, @ps[0], @pv[0]));
Result := pv[0];
finally
if ps <> nil then
FreeMem(ps);
if pv <> nil then
FreeMem(pv);
end;
end;
function TPropertySet.GetPropertyByName(
APropertyName: WideString): TPropVariant;
var
ps: PPropSpecArray;
pv: PPropVariantArray;
begin
ps := nil;
pv := nil;
try
GetMem(ps, sizeof(TPropSpec));
GetMem(pv, sizeof(TPropVariant));
OleCheck(FPropertyStorage.ReadMultiple(1, @ps[0], @pv[0]));
Result := pv[0];
finally
if ps <> nil then
FreeMem(ps);
if pv <> nil then
FreeMem(pv);
end;
end;
1: begin
cbPropertyName.Style := csDropDownList;
end;
2: begin
cbPropertyName.Style := csDropDown;
end;
end;
end;
function TfrmMain.Matches(P: TPropVariant): Boolean;
begin
case P.vt of
VT_LPSTR:
Result := UpperCase(P.pszVal) = UpperCase(ecValue.Text);
VT_I4:
Result := P.lVal = StrToInt(ecValue.Text);
// Handle other property types here...
else
Result := False;
end;
end;
procedure TfrmMain.btnFindClick(Sender: TObject);
var
SR: TSearchRec;
Res: Integer;
P: TPropVariant;
ID: Integer;
FileName: WideString;
begin
lbFiles.Items.Clear;
Res := FindFirst(ecFilePath.Text, faReadOnly or faArchive, SR);
if Res = 0 then
try
while Res = 0 do begin
FileName := ExtractFilePath(ecFilePath.Text) + SR.Name;
if StgIsStorageFile(PWideChar(FileName)) = S_OK then begin
PropertySet1.FileName := FileName;
PropertySet1.StreamGUID := StreamGuids[cbStream.ItemIndex];
PropertySet1.Open;
try
if cbStream.ItemIndex = 2 then begin
P := PropertySet1.GetPropertyByName(cbPropertyName.Text);
end else begin
ID := Integer(cbPropertyName.Items.Objects[cbPropertyName.ItemIndex]);
P := PropertySet1.GetPropertyByID(ID);
end;
if Matches(P) then
lbFiles.Items.Add(FileName);
finally
PropertySet1.Close;
end;
end;
Res := FindNext(SR);
end;
finally
FindClose(SR);
end;
if lbFiles.Items.Count = 0 then
ShowMessage('No matching files found.');
end;
procedure TfrmMain.btnCloseClick(Sender: TObject);
begin
Close;
end;
function ReadLink(AFileName: String):String;
var
psl: IShellLink;
ppf: IPersistFile;
WCLinkName: array[0..Max_Path] of WideChar;
Buf: array[0..255] of Char;
Data: TWin32FindData;
begin
psl:=CreateComObject(CLSID_ShellLink) as IShellLink;
ppf:=psl as IPersistFile;