Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi中的活动目录_Delphi_Active Directory - Fatal编程技术网

Delphi中的活动目录

Delphi中的活动目录,delphi,active-directory,Delphi,Active Directory,*我使用了以下代码: 但在广告搜索手柄上有一个错误 有人能帮我吗?* 代码: unit Unapp; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFormApp = class(TForm) Button1: TButton; private function GetADD

*我使用了以下代码: 但在广告搜索手柄上有一个错误 有人能帮我吗?*

代码:

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.
德尔菲误差; [错误]Unapp.pas(33):未声明的标识符:“ADS\u搜索\u句柄” [错误]UNAP.pas(70):实际和形式var参数的类型必须相同 [错误]unap.pas(70):不兼容的类型:“Char”和“WideChar” [错误]Unapp.pas(73):未声明的标识符:“CaseIgnoreString” [错误]UNAP.pas(74):实际和形式var参数的类型必须相同 [错误]unap.pas(77):实际和形式var参数的类型必须相同
[致命错误]ProjApp.dpr(5):无法编译使用过的单元“unap.pas”

看起来
DirSearch
未初始化

使用此代码对其进行初始化

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

别忘了用您的实际域替换您的域

您可以发布完整的错误消息并在代码中指出相应的行吗?您没有初始化
DirSearch
这里发布的是相同的代码吗?是的,我使用那个代码,但它不工作?因为广告,搜索,处理。你能帮我吗?嗨,亚历山大,我发了原始代码和德尔福错误,你能帮我吗?