SdsADGruppen.AddField(TStringField,fnADGrpName,fkData,50,false);
SdsADGruppen.AddField(TStringField,fnADGrpDescr,fkData,255,false);
SdsADGruppen.AddField(TStringField,fnADGUID,fkData,50,false);
SdsADGruppen.AddField(TStringField,'
distName',fkData,255,false);
SdsADGruppen.CreateDataSet;
SdsADGruppen.Edit;
if SUCCEEDED(ADsGetObject('
LDAP://'+vPath.str, IDirectorySearch, Search))
then
begin
try
opt.dwSearchPref := ADS_SEARCHPREF_SEARCH_SCOPE;
opt.vValue.dwType := ADSTYPE_INTEGER;
opt.vValue.__MIDL_0010.Integer := ADS_SCOPE_SUBTREE;
if not SUCCEEDED(search.SetSearchPreference(opt, 1))
then
begin
ADsGetLastError(dwErr, @szErr[0], 254, @szName[0], 254);
raise Exception.Create(WideCharToString(szErr));
Result := '
';
Exit;
end;
dwCount := Length(Properties);
hr := search.ExecuteSearch(StringToOleStr('
(objectCategory=' + Category + '
)'), @Properties[0], dwCount, ptrResult);
if SUCCEEDED(hr)
then
begin
hr := search.GetNextRow(ptrResult);
while (hr <> S_ADS_NOMORE_ROWS)
do
begin
SdsADGruppen.Append;
for idx := 0
to dwCount -2
do
begin
if Succeeded(search.GetColumn(ptrResult, Properties[idx], col))
then
begin
if col.pADsValues <>
nil then
begin
SearchText := col.pAdsValues^.__MIDL_0010.BackLink.ObjectName;
case idx
of
0 : SdsADGruppen.FieldByName(fnADGrpName).Value := SearchText;
1 : SdsADGruppen.FieldByName(fnADGrpDescr).Value := SearchText;
2 : SdsADGruppen.FieldByName('
distName').Value := SearchText;
//3 : SdsADGruppen.FieldByName(fnADGUID).Value := SearchText;
end;
end;
search.FreeColumn(col);
end;
end;
SdsADGruppen.FieldByName(fnADGUID).Value := '
{Dummy}';
SdsADGruppen.Post;
hr := search.GetNextRow(ptrResult);
//if SdsADGruppen.RecordCount > 900 then
//break;
end;
end;
finally
end;
end;