Note that there are some explanatory texts on larger screens.

plurals
  1. POSurprising error in a Delphi program
    text
    copied!<p>I am using <a href="https://stackoverflow.com/questions/337300/how-do-integrate-delphi-with-active-directory/339123#339123">this unit</a> in a Delphi 2010 application to tell me what Active Directory Groups a user is a member of.</p> <p>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.</p> <p>My code looks like this:</p> <pre><code>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; </code></pre> <p>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.</p> <pre><code>--------------------------- 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 --------------------------- </code></pre> <p>However, if I un-comment the block of code involving the TStringList, then it all works great.</p> <p>Either this is some really weird compiler bug, or I'm missing something obvious. Can someone help me out?</p> <p>The "adrec" structure is a simple record consisting of a few booleans, strings, and one other record (TPassword).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload