1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ValEdit, StdCtrls, DB, ExtCtrls, DBCtrls, DBGrids, ADODB,strutils;
type
TForm1 = class(TForm)
ADOConnection1 : TADOConnection;
ADOQuery1 : TADOQuery;
DataSource1 : TDataSource;
Button1 : TButton;
ListBox1: TListBox;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
ComboBoxQuoi: TComboBox;
Label3: TLabel;
ComboBoxTypeQui: TComboBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure RunConnexion(Sender: TObject);
procedure Terminer(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
sold:string;
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Adoquery1.Active := false;
adoquery1.Free;
adoconnection1.Close;
adoconnection1.Free;
end;
procedure TForm1.RunConnexion(Sender: TObject);
var Req, Qui, Quoi, TypeQui : string;
Save_Cursor : TCursor;
I, nb : integer;
FieldValNameVariant : variant;
begin
Save_Cursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
adoquery1.Active := false;
adoquery1.SQL.Clear;
Listbox1.Clear;
Qui := Edit1.Text;
Quoi := ComboboxQuoi.text;
TypeQui := ComboboxTypeQui.text;
if (Qui = '') then
showmessage('Il faut remplir le champs Qui')
else
begin
ADOConnection1.ConnectionString:='Provider=ADsDSOObject';
ADOConnection1.LoginPrompt:=false;
ADOConnection1.Connected:=true;
datasource1.DataSet := adoquery1;
Req := 'SELECT ' + Quoi + ' FROM ''LDAP://l'adresse de ton annuaire:389/o=Your Organization,c=fr'' WHERE objectClass = ''inetOrgPerson'' AND ' + TypeQui + ' = ''' + Qui + '''';
adoquery1.SQL.Add(Req);
try
adoquery1.Active := true;
nb := datasource1.DataSet.RecordCount;
if (nb > 0) then
begin
datasource1.DataSet.FindFirst;
FieldValNameVariant := datasource1.DataSet.FieldByName(Quoi).AsVariant;
if (not datasource1.DataSet.FieldByName(Quoi).IsNull) then
Listbox1.Items.Add(datasource1.DataSet.FieldByName(Quoi).AsVariant[0]);
end;
for I:=2 to nb do
if (datasource1.DataSet.FindNext) then
if (not datasource1.DataSet.FieldByName(Quoi).IsNull) then
Listbox1.Items.Add(datasource1.DataSet.FieldByName(Quoi).AsVariant[0]);
except
on E: Exception do
showmessage (E.Message);
end;
end;
Screen.Cursor := Save_Cursor; // Always restore to normal
end;
procedure TForm1.Terminer(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
ComboboxQuoi.clear;
ComboboxQuoi.Items.Add('sn');
ComboboxQuoi.Items.Add('cn');
ComboboxQuoi.Items.Add('givenName');
ComboboxQuoi.Items.Add('mail');
ComboboxQuoi.Items.Add('uid');
ComboboxQuoi.ItemIndex := 0;
ComboBoxTypeQui.clear;
ComboBoxTypeQui.Items.Add('sn');
ComboBoxTypeQui.Items.Add('cn');
ComboBoxTypeQui.Items.Add('givenName');
ComboBoxTypeQui.Items.Add('mail');
ComboBoxTypeQui.Items.Add('uid');
ComboBoxTypeQui.ItemIndex := 0;
end;
end. |
Partager