0

*私はこのコードを使用しました:しかし、ADS_SEARCH_HANDLEにエラーがあります。誰か助けてもらえますか?*

コード :

unit Unapp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TFormApp = class(TForm)
    Button1: TButton;
  private
     function GetADDisplayName(const Username: String): String;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormApp: TFormApp;

implementation
uses
  ActiveX,
  JwaAdsTlb, JwaActiveDS; // From Jedi ApiLib

{$R *.dfm}
function TFormApp.GetADDisplayName(const Username: String): String;
var
  hr: HRESULT;
  DirSearch: IDirectorySearch;
  SearchInfo: ADS_SEARCHPREF_INFO;
  hSearch: ADS_SEARCH_HANDLE; // ************this has error**************
  col: ADS_SEARCH_COLUMN;
  Filter: String;
  Attributes: array of PChar;
begin
  Result := 'Undefined Result';

  // Initialize COM
  CoInitialize(nil);

  try
    // Change line below with your domain name
    hr := ADsGetObject('LDAP://dc=Tbco,dc=com',
      IID_IDirectorySearch, Pointer(DirSearch));
    Win32Check(Succeeded(hr));

    SearchInfo.dwSearchPref   := ADS_SEARCHPREF_SEARCH_SCOPE;
    SearchInfo.vValue.dwType  := ADSTYPE_INTEGER;
    SearchInfo.vValue.dwType := ADS_SCOPE_SUBTREE;

    hr := DirSearch.SetSearchPreference(SearchInfo,1);
    Win32Check(Succeeded(hr));

    Filter := Format('(&(objectClass=user)(sAMAccountName=%s))',
      [Username]);

    SetLength(Attributes, 1);
    Attributes[0] := 'displayName';

    // When using Dynamic Array with WinApi ALWAYS use pointer to first element!
    hr := DirSearch.ExecuteSearch(PWideChar(Filter),PWideChar(Attributes[0]),Length(Attributes), Pointer(hSearch));
    Win32Check(Succeeded(hr));

    try
      hr := DirSearch.GetFirstRow(Pointer(hSearch));
      Win32Check(Succeeded(hr));

      hr := DirSearch.GetColumn(hSearch, Attributes[0], col);
      if Succeeded(hr) then
      begin
        Result := col.pADsValues^.CaseIgnoreString;
        DirSearch.FreeColumn(@col);
      end;
    finally
      DirSearch.CloseSearchHandle(hSearch);
    end;
  finally
    // UnInitialize COM
    CoUninitialize;
  end;
end;

end.

Delphi エラー。[エラー] Unapp.pas(33): 宣言されていない識別子: 'ADS_SEARCH_HANDLE' [エラー] Unapp.pas(70): 実際の変数パラメーターと正式な変数パラメーターの型は同一でなければなりません [エラー] Unapp.pas(70): 互換性のない型: ' Char' および 'WideChar' [エラー] Unapp.pas(73): 宣言されていない識別子: 'CaseIgnoreString' [エラー] Unapp.pas(74): 実際の変数パラメーターと正式な var パラメーターの型は同一である必要があります [エラー] Unapp.pas(77 ): 実際の var パラメーターと正式な var パラメーターの型は同一である必要があります [致命的なエラー] ProjApp.dpr(5): 使用されているユニット 'Unapp.pas' をコンパイルできませんでした

4

1 に答える 1

0

DirSearch初期化されていないようです

このコードを使用して初期化します

    AdsGetObject(PWideChar('LDAP://YourDomain'), IDirectorySearch, DirSearch);

YourDomain を実際のドメインに置き換えることを忘れないでください

于 2013-10-28T23:25:17.203 に答える