Hier ein Beispiel eines alten Programms:
Delphi-Quellcode:
FDomain : String;
FDomainName : String;
LRoot : TTreeNode;
type
PNodeData = ^TNodeData;
TNodeData = class(TObject)
private
FName : String;
FClassName: String;
FFullPath : String;
procedure SetName(Value : String);
public
property Name : String read FName write SetName;
property CName : String read FClassName write FClassName;
property FullPath : String read FFullPath;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
FDomainName := '';
CoInitialize(nil);
GetLDAPDomain;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
CoUninitialize;
end;
procedure TMainForm.GetLDAPDomain;
var
NSContainer : IADsContainer;
Enum : IEnumVariant;
hr : integer;
varArr : OleVariant;
lNumElements : ULONG;
item : IADs;
s : String;
RN : TTreeNode;
begin
tvLDAP.Items.Clear;
NSContainer := nil;
ADsGetObject( 'LDAP:', IADsContainer, NSContainer);
Enum := nil;
RN := tvLDAP.Items.Add(nil, 'Active Directory');
RN.ImageIndex := 0;
hr := ADsBuildEnumerator(NSContainer,Enum);
while SUCCEEDED(hr) do
begin
hr := ADsEnumerateNext(Enum, 1, varArr, lNumElements);
if (lNumElements<=0) then Break;
IDispatch(varArr).QueryInterface(IADs, item);
s := item.ADsPath;
LRoot := tvLDAP.Items.AddChild(RN, s);
LRoot.Data := TNodeData.Create;
TNodeData(LRoot.Data).Name := Item.ADsPath;
TNodeData(LRoot.Data).CName := Item.Class_;
LRoot.ImageIndex := 1;
LRoot.SelectedIndex := 1;
end;
end;
Probiere es mal, wenn es läuft dann hast du
CoInitialize(nil); vergessen.