title: How do I fix an Access Violation in Delphi if it worked in previous code?
body: <p>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?</p>
  
  <p>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? </p>
  
  <p>WORKING  CODE:</p>
  
  <pre><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;
  </code></pre>
  
  <p>PROBLEM CODE:</p>
  
  <pre><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;
  </code></pre>
  
  <p>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 <code>Items</code>, but nothing of that sort happens at all.</p>