Search code examples
databasedelphi

Delphi database search


I'm working on a small app with login by mail/password which uses a database. In this database, the following are stored:

  • client number
  • client Mail
  • Client Password
  • Client Available credits

For login I check user mail/password in DB with this code:

if not (tbl1.Locate('Mail', edt1.text,[]) and tbl1.Locate('Password', edt2.text,[]) ) then
   begin
    mmo1.lines.add('Not Registered User');
   end
   else
   begin
    mmo1.lines.add('Registered User');
   end;
end;

This works for login. My problem is with credits. For example user John has 10 credits.

I cannot use locate here

How can I get the available amount of credits of John from the database?


Solution

  • Use multiple fields in the locate: see Using locate

    if  (tbl1.Locate('Mail; Password', VarArrayOf([edt1.text, edt2.text]),[])) then 
    begin
      mmo1.lines.add('Registered User: '+ tbl1.FieldByName('credits').asString);
    end
    else
    begin
      mmo1.lines.add('Not Registered User');
    end;