Domanda

La seguente pagina web descrive l'interrogazione di ricerca di Windows a livello di codice:

http://msdn.microsoft.com/en-us/library /aa965362.aspx

Qualcuno ha esempi utilizzando Delphi / Pascal?

Gli esempi che ho in mente sono abbastanza semplici:

  1. Cerca per alcuni tipi di file.
  2. la ricerca di testo all'interno di file specifici.
  3. limite queste ricerche di cui sopra ad un certo percorso.
È stato utile?

Soluzione

Ecco quello che ho fatto qualche tempo fa - essere consapevoli che potrebbe non essere aggiornato:

const
  GENERAL_COLUMNS = '"System.Itemname", "System.Size", "System.DateCreated", "System.ItemDate",' +
                    '"System.ItemFolderPathDisplay", "System.Search.AutoSummary", "System.ItemType"';

  IMAGE_COLUMNS = '"System.Image.HorizontalSize", "System.Image.VerticalSize", '+
                  '"System.Image.BitDepth", "System.Image.Compression", '+
                  '"System.Photo.CameraModel", "System.Photo.DateTaken", "System.Photo.Flash"';
  MUSIC_COLUMNS = '"System.Music.Artist", "System.Music.Genre", "System.Music.TrackNumber", '+
                  '"System.Audio.Compression", "System.Audio.SampleRate", '+
                  '"System.DRM.IsProtected", "System.Music.AlbumTitle", "System.Rating", '+
                  '"System.Audio.EncodingBitrate"';

procedure TWDSDataSource.RetrieveDataFromDB;
var
  manager : ISearchManager;
  catalogManager : ISearchCatalogManager;
  queryHelper : ISearchQueryHelper;
  wQuery : string;
  temp : PWideChar;
  sTemp : string;
begin
  manager := CoCSearchManager.Create;
  if Succeeded(manager.GetCatalog('SystemIndex',catalogManager)) then
  begin
    if Succeeded(catalogManager.GetQueryHelper(queryHelper)) then
    begin
      if fMaxResults  0 then
        queryHelper.Set_QueryMaxResults(fMaxResults);

      queryHelper.Set_QuerySelectColumns(GENERAL_COLUMNS + ',' + MUSIC_COLUMNS + ',' + IMAGE_COLUMNS);
      queryHelper.GenerateSQLFromUserQuery(PWideChar(fQuery),temp);
      wQuery := temp;

      queryHelper.Get_ConnectionString(temp);
      sTemp := temp;
      dataset := CreateComObject(CLASS_Recordset) as _Recordset;
      dataset.CursorLocation := adUseClient;
      dataset.Open(wQuery, stemp, adOpenForwardOnly, adLockReadOnly, adCmdText);
      dataset.Set_ActiveConnection(nil);
      bDatabaseFailed := false;
    end else
      bDatabaseFailed := true;
  end else
    bDatabaseFailed := true;
end;

Credo che sia tutto piuttosto auto esplicativo, fJobStep è la query che si desidera eseguire.

Saluti Keith

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top