Resolved. The debugger is your friend.

This library has very nice code and my compliments to it's author.


Even though this isn't a Lazarus site, I'm throwing my example out

1. Added a Combobox to my form

2. Created the below procedure


procedure LDAPResult_GetEmail(const Value: TLDAPResultList; cb: TComboBox);
var
  n, m, o: integer;
  r: TLDAPResult;
  a: TLDAPAttribute;
begin
  for n := 0 to Value.Count - 1 do
  begin
    r := Value[n];
    for m := 0 to r.Attributes.Count - 1 do
    begin
      a := r.Attributes[m];
      for o := 0 to a.Count - 1 do
       cb.Items.Add (a[0]);
    end;
  end;
end;


Ended up with the following.

I pass the ComboBox to the function and load there.

procedure TForm1.Button1Click(Sender: TObject);
var
  ldap: TLDAPsend;
  l: TStringList;
  al: TLDAPAttribute;
  s: string;

begin
  ldap:= TLDAPsend.Create;
  l := TStringList.Create;
  al := TLDAPAttribute.Create ;
  memo1.Lines.Clear ;
  try
     ldap.TargetHost := '192.168.40.50';
     ldap.UserName := 'administra...@internal.machinemanagement.com';
     ldap.Password := 'TUCSON686f70';


    if ldap.Login then
      if ldap.Bind then
      begin
          ShowMessage('Connected to LDAP');
          l.Add('displayname');
          //l.Add('description');
          //l.Add('givenName');
          l.Add('mail');
          //l.Add('*');
ldap.Search('OU=Users,OU=MM,DC=internal,DC=machinemanagement,DC=com', False, '(objectclass=*)', l);

          LDAPResult_GetEmail (ldap.SearchResult, attributelist);

          ldap.Logout;
      end;
  finally
    ldap.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

  application.Terminate ;
end;


procedure LDAPResult_GetEmail(const Value: TLDAPResultList; cb: TComboBox);
var
  n, m, o: integer;
  r: TLDAPResult;
  a: TLDAPAttribute;
begin
  for n := 0 to Value.Count - 1 do
  begin
    r := Value[n];
    for m := 0 to r.Attributes.Count - 1 do
    begin
      a := r.Attributes[m];
      for o := 0 to a.Count - 1 do
       cb.Items.Add (a[0]);
    end;
  end;
end;



































On 4/9/2023 10:57 AM, Bret Stern wrote:
Good afternoon,

I have the example ldap working in Lazarus IDE, which displays the LDAP search in the Memo control.

I need some suggestion to retrieve the results into a list box. I think I need the TLDAPAttribute, but not sure.

What should I use to pull the attributes from the ldapsearch?

My goal is to populate an email client application with email addresses from the DC.

Very best regards,

Bret Stern

Here is my sample:

procedure TForm1.Button1Click(Sender: TObject);
var
  ldap: TLDAPsend;
  l: TStringList;
  al: TLDAPAttribute;
  s: string;



begin
  ldap:= TLDAPsend.Create;
  l := TStringList.Create;
  al := TLDAPAttribute.Create ;

  try
     ldap.TargetHost := '192.168.40.50';
     ldap.UserName := 'administra...@internal.domain.com';
     ldap.Password := 'PASSWORD123';


    if ldap.Login then
      if ldap.Bind then
      begin
          ShowMessage('Connected to LDAP');
          //l.Add('displayname');
          //l.Add('description');
          //l.Add('givenName');
          l.Add('mail');
          //l.Add('*');
ldap.Search('OU=Users,OU=MM,DC=internal,DC=domain_name,DC=com', False, '(objectclass=Person)', l);

          //al.Values.  := ldap.SearchResult.UnitName ;

          //memo1.Lines.Add(LDAPResultDump(ldap.SearchResult));
          //memo1.Lines.Add
        ldap.Logout;
      end;
  finally
    ldap.Free;
  end;
end;





_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public


_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to