Hello,
Pourquoi ne pas, tout simplement, utiliser une requête ?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Db, DbTables;
type
TRecSearchResult = (srCanceled, srNotFound, srFound);
TForm1 = class (TForm)
Button1: TButton;
Table1: TTable;
procedure Button1Click(Sender: TObject);
private
function Recherche: TRecSearchResult;
end;
var
Form1: TForm1;
implementation
resourcestring
sEnregistrementIntrouvableDansLaT = 'Enregistrement introuvable dans la table';
sEntrerLeNomDeLaPersonne = 'entrer le nom de la personne :';
sEntrerLePrenomDeLaPersonne = 'entrer le prénom de la personne :';
sRecherche = 'Recherche';
{$R *.dfm}
function TForm1.Recherche(): TRecSearchResult;
var
nom, prenom: string;
Q: TQuery;
begin
Result : = srNotFound;
nom := InputBox(sRecherche, sEntrerLeNomDeLaPersonne, '');
prenom := InputBox(sRecherche, sEntrerLePrenomDeLaPersonne, '');
if (nom EmptyStr) <gras>and (prenom</gras> EmptyStr) then
begin
Result := srCanceled;
Exit;
end ;
nom : = QuotedStr(nom);
prenom := QuotedStr(prenom);
Q := TQuery.Create(self);
try
Q.DataBaseName := Table1.DataBaseName; Q.SQL.Text :'SELECT * FROM maTable WHERE nom :nom';
Q.ParamByName('nom').AsString := nom;
if prenom <> EmptyStr then
begin
Q.Sql.Add('AND prenom = :prenom');
Q.ParamByName('prenom').AsString := prenom;
end ;
Q.Open;
if Q.RecordCount > 0then
Result : = srFound;
finally
FreeAndNil(Q);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Recherche = srNotFound then
MessageDlg(sEnregistrementIntrouvableDansLaT,mtInformation,[mbOk], 0);
end ;
end.
Ce code n'est qu'un exemple simple pour illustrer la méthode préconisée.
May Delphi be with you !
<hr color ="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
http://www.afipa.net/