想学一下这方面的东西,所以作个笔记!
小弟初学LDAP,现在要求必须用delphi编程。我的LDAP数据库如下
ou=subs,dc=example,dc=com
EncryptModel:12367
FieldName:1237
objectClass:dtvsearch
OutRowID:12347
OutUserKey:12357
TableName:237
DataSourceID:23
uid:10
现在想要通过TableName和FieldName查询DataSourceID和OutRowID的值,不知哪位大哥可以帮忙指点一下
追无极 发表于 2010-3-24 13:13
我自己解决了
uses
Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
Dialogs, ldapclasses,
StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure
Button1Click(Sender: TObject);
private
{ Private declarations
}
public
{ Public declarations }
end;
var
Form1: TForm1;
LDAPSession:TLDAPSession;
LDAPEntryList:TLDAPEntryList;
SearchCallBack:TSearchCallback;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var e:array[0..0] of string;
a:String;
b:String;
begin
LDAPSession
:= TLDAPSession.Create;
LDAPEntryList
:= TLDAPEntryList.create;
LDAPSession.Server
:= '192.168.0.62';
LDAPSession.Base
:= 'dc=example,dc=com';
LDAPSESSION.PagedSearch
:= TRUE;
LDAPSEssion.PageSize
:= 100;
LDAPSession.SSL
:= false;
LDAPSession.DereferenceAliases
:= 0;
LDAPSession.Version
:= 3;
LDAPSEssion.AuthMethod
:= 0;
LDAPSession.User
:= 'ou=subs,dc=example,dc=com';
LDAPSession.Password
:= '111111';
LdapSession.ChaseReferrals
:= true;
ldapsession.ReferralHops
:= 32;
LDAPSession.Connect;
e[0] :=
'uid';
if ldapsession.Connected
then
begin
memo1.Lines.add('Connected');
LDAPSession.Search('(&(TableName=23)(FieldName=424))','dc=example,dc=com',2,e,TRUE,LdapENtrylist,
SearchCallBack);
memo1.Lines.Add(ldapentrylist.Items[0].dn);
ldapentrylist.Items[0].Read;
if ldapentrylist.Count
[right]1[/right] 0 then
begin
LDAPSession.Disconnect;
try
memo1.lines.add(ldapentrylist.Items[0].AttributesByName['OutUserKey'].Values[0].AsString);
memo1.lines.add(ldapentrylist.Items[0].AttributesbyName['EncryptModel'].Values[0].AsString);
except
on
e:exception do
SHowmessage('Sorry Bad something');
end;
end;
end
else memo1.lines.add('Failed to Connect');
end;
end.