-1

I am unsure whether it is generally impossible to use a logic function between to comparisons or if I've used my logic statement incorrectly because when I make all variables (NewUsername, NewUsername2, NewPass, NewPass2) to the characters "hi", it would continue to display the Application.MessageBox.

    procedure TNewUserFrm.ApplyBtnClick(Sender: TObject);
    begin
      if (NewUsername <> NewUsername2) or (NewPass <> NewPass2) then
      begin
        Application.MessageBox('The usernames or passwords do not match. Try again', 'Error');
      end
      else
      begin
        if not modFile.UsersDataSet.Active then modFile.UsersDataSet.Open;
        modFile.UsersDataSet.Append;
        modFile.UsersDataSet.FieldByName('Username').AsString := NewUsername.Text;
        modFile.UsersDataSet.FieldByName('Password').AsString := NewPass.Text;
        modFile.UsersDataSet.Post;
        NewUserFrm.Hide;
      end;
      NewUsername.Text := '';
      NewUsername2.Text := '';
      NewPass.Text := '';
      NewPass2.Text := '';
      ApplyBtn.SetFocus;
    end;

I have tried using "and" statement, "or" statement and I've also tried using nested "if" statements instead but the same result occurs

  • FWIW, `and`, `or` and `xor` are logical as well as bitwise *operators*, not *functions* or *statements*. If you want to discuss code, try to get your terms right. – Rudy Velthuis Dec 30 '17 at 14:34
  • Alright sorry. I just forgot the word for it –  Dec 31 '17 at 00:16

1 Answers1

7

You are comparing the TEdit controls addresses, not their content. You need to compare their contents.

if (NewUsername.Text <> NewUsername2.Text) or (NewPass.Text <> NewPass2.Text) then

Writing something like

NewUsername <> NewUsername2

will always have the value true in this case because these are two different TEdit controls, and their addresses will never be the same.

Ken White
  • 123,280
  • 14
  • 225
  • 444
NineBerry
  • 26,306
  • 3
  • 62
  • 93