Einzelnen Beitrag anzeigen

Benutzerbild von stOrM
stOrM

Registriert seit: 7. Jun 2003
Ort: Mülheim an der Ruhr
434 Beiträge
 
Delphi 10.3 Rio
 
#4

Re: Vista Suche in Delphi nutzen

  Alt 12. Feb 2009, 05:08
Hmmm, scheint ja ein echt kompliziertes Thema zu sein, oder es interessiert mal wieder nur mich
Ich hab mal ein wenig weiter gefummelt und bekomm jetzt wenigstens ein wenig Informationen bevor es dann wieder kracht!

Vielleicht mag mal jemand drüber kucken, dass Problem ist irgendwie das ich den Fehler nicht lokalisieren kann, da ich nicht weiß, ob der Fehler nun am Query liegt, an Ado, oder an der TLB selber. Nun ja mit einer Fehlermeldung "unbekannter Fehler" läßt sich auch schlecht arbeiten

So mal ein bischen Code:

Delphi-Quellcode:
  public
    { Public-Deklarationen }
    pSearchMgr : ISearchManager;
    pSearchCatMgr : ISearchCatalogManager;
    pQueryHelper : ISearchQueryHelper;

    pCatStat,
    pReason : TOleEnum;

    pInxCount : Integer;
    pIndexedUrl : PWideChar;

    pConnectionString : PWideChar;
    pConnectionTimeOut : Cardinal;
    pQuery,
    pSQL : PWideChar;
    pSearchString : PWideChar;

...

procedure TMainForm.FormShow(Sender: TObject);
var
  pReasonRes : string;
begin
  pSearchMgr := CoCSearchManager.Create;

  try
    // the valid catalog is systemindex only!
    pSearchMgr.GetCatalog('SYSTEMINDEX', pSearchCatMgr);

    // get some stats: pStatus, pPausedReason
    pSearchCatMgr.GetCatalogStatus(pCatStat, pReason);

    case pReason of
      CATALOG_PAUSED_REASON_NONE: pReasonRes := 'none';
      CATALOG_PAUSED_REASON_HIGH_IO: pReasonRes := 'high io';
      CATALOG_PAUSED_REASON_HIGH_CPU: pReasonRes := 'high cpu';
      CATALOG_PAUSED_REASON_HIGH_NTF_RATE: pReasonRes := 'high ntf rate';
      CATALOG_PAUSED_REASON_LOW_BATTERY: pReasonRes := 'low battery';
      CATALOG_PAUSED_REASON_LOW_MEMORY: pReasonRes := 'low memory';
      CATALOG_PAUSED_REASON_LOW_DISK: pReasonRes := 'low disk';
      CATALOG_PAUSED_REASON_DELAYED_RECOVERY: pReasonRes := 'delayed recovery';
      CATALOG_PAUSED_REASON_USER_ACTIVE: pReasonRes := 'user active';
      CATALOG_PAUSED_REASON_EXTERNAL: pReasonRes := 'external';
      CATALOG_PAUSED_REASON_UPGRADING: pReasonRes := 'upgrading';
    end;

    case pCatStat of
      CATALOG_STATUS_IDLE: lblStatus.Caption := Format('Status: %0:s reason: %1:s', ['idle', pReasonRes]);
      CATALOG_STATUS_PAUSED: lblStatus.Caption := Format('Status: %0:s reason: %1:s', ['paused', pReasonRes]);
      CATALOG_STATUS_RECOVERING: lblStatus.Caption := Format('Status: %0:s reason: %1:s', ['recovering', pReasonRes]);
      CATALOG_STATUS_FULL_CRAWL: lblStatus.Caption := Format('Status: %0:s reason: %1:s', ['full crawl', pReasonRes]);
      CATALOG_STATUS_INCREMENTAL_CRAWL: Format('Status: %0:s reason: %1:s', ['incremental crawl', pReasonRes]);
      CATALOG_STATUS_PROCESSING_NOTIFICATIONS: Format('Status: %0:s reason: %1:s', ['notifications', pReasonRes]);
      CATALOG_STATUS_SHUTTING_DOWN: Format('Status: %0:s reason: %1:s', ['shutting down', pReasonRes]);
    end;

    // how many items indexed
    pSearchCatMgr.NumberOfItems(pInxCount);
    lblIdxCount.Caption := Format('Items currently indexed: %d', [pInxCount]);

    // get indexed file
    pSearchCatMgr.URLBeingIndexed(pIndexedUrl);
    lblIndexer.Caption := Format('Last indexed %s', [pIndexedUrl]);

    // ISearchQueryHelper interface
    pSearchCatMgr.GetQueryHelper(pQueryHelper);

    // get timeout value
    pSearchCatMgr.Get_ConnectTimeout(pConnectionTimeOut);

    // get the connectionstring for connection to the oledb
    pQueryHelper.Get_ConnectionString(pConnectionString);

    // connect to oledb using the pconnectionstring {adoconnection}
    con.ConnectionString := pConnectionString;
    con.ConnectionTimeout := pConnectionTimeOut;
    Con.LoginPrompt := False;
    con.Connected := True;

  except
   on E: EOleException do
   begin
     ShowMessage(E.Message);
   end;
  end;

end;

// hier gehts los
procedure TMainForm.btnSearchClick(Sender: TObject);
begin

 pQuery := 'SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX';

  try
   // query helper generates a valid sql string...
   pQueryHelper.GenerateSQLFromUserQuery(pQuery, pSql);


   qry.SQL.Text := pSQL;
   qry.Active := True; // hier kracht es aber gewaltig!

  except
  on e: Exception do
  begin
    ShowMessage(E.Message);
    end;
  end;

end;

initialization
  CoInitializeEx(nil, COINIT_MULTITHREADED);

finalization
  CoUninitialize;
end.
Vielleicht sollte ich noch erwähnen, dass ich die Exe unter Vista nur mit Adminrechten starten kann, weil sonst knallts schon bei der Ausführung!

Hier noch ein paar Links zu dem Thema falls jemand in die Thematik mit einsteigen mag:

danielmoth
devx
MSDN

Getestet wurde das ganze unter Vista Ultimate 32 Bit EN / DE mit Delphi 2009 Architect Sp1 incl. DB Update 1 sowie Help Update
Na dann hoff ich mal, dass mir da jemand auf die sprünge helfen kann!
Viele Grüsse
Marc
Angehängte Dateien
Dateityp: pas searchapilib_tlb_269.pas (62,9 KB, 11x aufgerufen)
  Mit Zitat antworten Zitat