0

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'

2
  • Can you show the code that's failing and provide specific error messages that you receive? Commented Sep 17, 2013 at 18:24
  • Hay guys when i posted this question I was still programming stupid and did not think to build my queries in my classes and then just return it to my main program. Thank you all for help i do appreciate it and i will keep these tips in mind. BTW i now code in C# rather then delphi but principles stay the same. Commented Nov 1, 2015 at 1:41

1 Answer 1

1

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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.