Help - incompatible type error. lazarus / 16-Databases ---------------------------------------------------------------------- Muggy · 2015-02-22 22:07 I am trying to get a simple username and password program to work, it checks the username is correct and then checks if the password is correct afterwards. The username and password are stored in an SQL database. I have yet to add in password checking as that is the same as username checking but username checking is not working. Here is all the relevent code   var   UsernameEnt, //stores the username and password the user entered   PasswordEnt,   UsernameCur, //stores the current username and password being checked in the database   PasswordCur,   hold //for holding the current query in the form of text   :String;   IDCur   :Integer=0; //stores the current id begin   UsernameEnt:=Username.text;   PasswordEnt:=Password.text;   while not adminform.adminquery.Eof do   begin     IDCur:=IDCur+1;     hold:='SELECT User FROM loginInf WHERE PKey='+IntToStr(IDCur)+';';     adminform.adminquery.Active:=true;     if (adminform.adminquery.SQL.text:=hold)=UsernameEnt then      //login succesful      Indicatortext.caption:='Welcome!';      IndicatorColour.Color:=$00FF00;      Application.createform(TAdminform,AdminForm);      LogInForm.hide;      Adminform.showmodal;      else   end;   //login unsuccesful   Indicatortext.caption:='nah!';   IndicatorColour.Color:=$0000FF; And the error I get is adminsignin.pas(57,8) Error: Incompatible types: got "untyped" expected "AnsiString" where line 57 is  if (adminform.adminquery.SQL.text:=hold)=UsernameEnt then Please help and ask for further clarification if this is at all unclear. Sorry i am new here, sorry if this is in the wrong subforum. ---------------------------------------------------------------------- Leledumbo · 2015-02-22 23:56 Assignment is a statement, not an expression, it has no value. ---------------------------------------------------------------------- Muggy · 2015-02-23 00:09 I am afraid i dont know what that means, could you explain in more detail. Perhaps hint at how i would fix this. ---------------------------------------------------------------------- engkin · 2015-02-23 01:08 What are you trying to do in line 57? ---------------------------------------------------------------------- Leledumbo · 2015-02-23 05:47 Quote from: Muggy on February 23, 2015, 01:09:46 amI am afraid i dont know what that means, could you explain in more detail. Perhaps hint at how i would fix this. Then google it. Hint to fix: you can't compare something that has no type (statement) with something else that has a type (expression). ---------------------------------------------------------------------- Muggy · 2015-02-23 08:20 Quote from: engkin on February 23, 2015, 02:08:44 amWhat are you trying to do in line 57? I am trying to check if the username at a specific primary key which is stepped matches the username the user has entered, and if it does then it will run the for loop. ---------------------------------------------------------------------- engkin · 2015-02-23 08:31 Quote from: Muggy on February 23, 2015, 09:20:02 amQuote from: engkin on February 23, 2015, 02:08:44 amWhat are you trying to do in line 57? I am trying to check if the username at a specific primary key which is stepped matches the username the user has entered, and if it does then it will run the for loop. I don't think this is the right way to use Pascal or SQL. ---------------------------------------------------------------------- mangakissa · 2015-02-23 08:52 First of all, this is more readdable: Code: [Select]var Username  :String;     Password  :String; begin   Username :=Username.text;   Password :=Password.text;   if locate('username;password',vararrayof([Username,Username]),[]) then     showmessage('Welcome!')   else     showmessage('Incorrect'); end; Never let you loginscreen the mainform. Let the mainform startup your loginprocedure. Code: [Select]//--mainform procedure TMainform.onShow(senter : TObject); var LoginForm : TLoginForm begin   LoginForm := TLoginForm.create(nil);   try     LoginForm.showmodal;     if LoginForm.loggedin then       showmessage('Welkome')   finally     LoginForm.free;   end;  end; //loginform type TLoginform : class(TForm); ...... public   loggedin : boolean;   ...... end; procedure TLoginform.OnCreate(sender : tobject); begin   loggedin := false; end procedure TLoginform.OnButton1Click(sender : tobject); var MyQuery : TQuery; begin   MyQuery := TQuery.create(nil);   try      MyQuery.connection := MyConnection;      MyQuery.SQL.Text := 'SELECT count(username) AS sum_of_rows FROM users WHERE username = :par1 AND password : par2';      MyQuery.Params[0].AsString := EUserName.text;      MyQuery.Params[1].AsString := EPassword.text;      MyQuery.active := true;      if MyQuery.fieldbyname('sum_of_rows').AsInteger = 1 then      begin        loggedin := true;      end else        showmessage('Wrong username or password');     finally     MyQuery.free;   end; end This is only an example. If you're using SQLdb, don't forget transactions. The best thing is put your idea on paper. work it out with a PSD Then create logical code on your program. Is this your first time?