I am using this unit in a Delphi 2010 application to tell me what Active Directory Groups a user is a member of.
I created a brand-new test vcl forms application, added the unit from that link, and made a little form with an edit box for the username, another edit box to hold the CSV separated list of groups, and a list box to hold the list of groups in a columnar format.
My code looks like this:
procedure TfrmMain.btnShowGroupsClick(Sender: TObject);
var
ad: TADSI;
adrec: TADSIUserInfo;
csvGroups: string;
slGroups: TStringList;
begin
//take username from an edit box, tell me what AD groups they are a member of
ad := TADSI.Create(Self);
try
ad.GetUser(edtDomain.Text,edtUser.Text,adrec);
csvGroups := adrec.Groups;
edtADGroups.Text := csvGroups; //ACCESS VIOLATION!!
finally
FreeAndNil(ad);
end;
{
//If I UN-comment this code, and make NO OTHER CHANGES, then the
//aforementioned access violation does NOT occur; there are no errors @ all,
//and everything works just fine
slGroups := TStringList.Create;
try
slGroups.CommaText := csvGroups;
listBoxADGroups.Items := slGroups;
finally
FreeAndNil(slGroups);
end;
//}
end;
If I run this code as-is, I get an access violation when I try to assign the CSV list of group to the edit box.
---------------------------
Debugger Fault Notification
---------------------------
Project C:\Users\my_username.mydomain\bin\ADSITest.exe faulted with message: 'access violation at 0x0048a321: read of address 0x458c0035'. Process Stopped. Use Step or Run to continue.
---------------------------
OK
---------------------------
However, if I un-comment the block of code involving the TStringList, then it all works great.
Either this is some really weird compiler bug, or I'm missing something obvious. Can someone help me out?
The "adrec" structure is a simple record consisting of a few booleans, strings, and one other record (TPassword).