1

This is for a login form, where I want to insert the username values from a user database into a ComboBox, but everything I've tried ends in an access violation error. I've tried all available connections and tables and it's the same problem with every one. What do I have to do to fix it, or prevent the error from appearing?

I've tried to replace the correct code into the procedure and it still aggravates me with the same error. Should I create a button for it or something?

WORKING CODE:

procedure TfrmTekenIN.btnTekenInClick(Sender: TObject);
var
  sPassword, sUPassword, sUserName, sKeyUserName : string;
begin
  sUPassword := edtPassword.Text;
  sKeyUserName := edtUsername.Text;

  with dmConnections do
  begin
    tblLogin.Open;
    tblLogin.First;
    while not tblLogin.Eof do
    begin
      sUserName := tblLogin.FieldByName('GebruikerNaam').Value;
      sPassword := tblLogin.FieldByName('Wagwoord').Value;

      if not (sUserName = sKeyUserName) then
      begin
        tblLogin.Next;
      end
      else if (sUserName = sKeyUserName) then
      begin
        if not (sPassword = sUPassword) then
        begin
          ShowMessage('Wagwoord is inkorrek! Probeer asseblief weer');
          Exit;
          edtPassword.SetFocus;
        end
        else if (sPassword = sUPassword) then
        begin
          frmToernooi.Show;
          frmTekenIN.Close;
        end;
      end; //nest-if
    end; //while
    //tblLogin.Close;
  end;
end;

PROBLEM CODE:

procedure TfrmTekenIN.FillComboBox;
var
  sUserName: string;
begin
  cboUsers.Items.Clear;  //clear combo box items

  with dmConnections do  //no errors if this stands alone
  begin
    tblLogin.Open;   //error will indicate here or anywhere where "tblLogin is written in"
    tblLogin.First;
    while not tblLogin.Eof do
    begin
      sUserName := tblLogin.FieldByName('GebruikerNaam').Value;
      cboUsers.Items.Add(sUserName); // add the value received from database  (connection on datamodule and adoTable)
      tblLogin.Next;
    end;
  end;
end;

I get access violation at address 00..84 every time it executes. when I select "Break" it shows the error at the tbl I use, but in a different procedure the assigned table works and there is no problem with it. I expect the values of the username field to be read into the ComboBox's Items, but nothing of that sort happens at all.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Mel Meyer
  • 11
  • 1
  • Possible duplicate of [Debugging Access Violation errors?](https://stackoverflow.com/questions/6214458/debugging-access-violation-errors) – David Heffernan Aug 11 '19 at 16:17
  • The most likely culprit is either 1) `FillComboBox()` is being called on an invalid `TfrmTekenIN` object, or 2) `dmConnections` is invalid at the time `FillComboBox()` is called. – Remy Lebeau Aug 12 '19 at 07:29

0 Answers0