Reputation: 176
I have created a class that has to use SQL-code to do a validation check from my database but when i try to run my program it does not use the ADOquery from my form. I have tried to fix it by adding my main unit to my class's unit but it then gives a circulation error. I have also tried to add Form1 into the uses(that is the name of my form and i only have one form) but then it does not understand Form1. If any one can help, it would be very appreciated.
orait this is in my class:
procedure TCheckA.CheckIfAdmin;
var iRecordA : Integer;
begin
qryInfo.Active := False;
qryInfo.SQL.Clear;
qryInfo.SQL.Add(' Select [Lid Naam], [Lid Wagwoord], Adminustrateur ');
qryInfo.SQL.Add(' From [CATSA Lede] ');
qryInfo.SQL.Add(' Where [Lid Naam] = "'+fgebruikernaam+'"and [Lid Wagwoord] = "'+fpassword+'" and Adminustrateur = True ');
qryInfo.Active := True;
iRecordA := qryinfo.recordcount;
if iRecordA = 1
then begin
fAdminAnswer := True;
end
else begin
fAdminAnswer := False;
end;
end;
Then it throughs this error: [Error] IntekenCheck.pas(29): Undeclared identifier: 'qryInfo'
Then if i try to put my main unit in my class's unit Like:
unit IntekenCheck;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Buttons, jpeg, ExtCtrls, XPMan, Grids,
DBGrids, DB, ADODB, Math, AdminCheck, Chairmin_u{main unit};
Then the error is: [Fatal Error] IntekenCheck.pas(7): Circular unit reference to 'IntekenCheck'
Upvotes: 0
Views: 392
Reputation: 125707
Pass the query into your class, and use it there:
procedure TCheckA.CheckIfAdmin(const Query: TAdoQuery);
begin
AQuery.Active := False;
AQuery.SQL.Clear;
AQuery.SQL.Add(' Select [Lid Naam], [Lid Wagwoord], Adminustrateur ');
AQuery.SQL.Add(' From [CATSA Lede] ');
AQuery.SQL.Add(' Where [Lid Naam] = "' + fgebruikernaam +
'"and [Lid Wagwoord] = "'+ fpassword +
'" and Adminustrateur = True ');
AQuery.Active := True;
fAdminAnswer := (AQuery.RecordCount = 1);
end;
(You should also change to use parameterized queries instead rather than contatenation with +
. It's much more secure. There are many other questions here relating to parameterized queries and Delphi; a quick search on [delphi] parameter query
should find them for you.)
Upvotes: 1