Delphi ComboBox Access violation on combobox

888 views Asked by At

I get Access violation error, but I know the code is correct, so where could be the problem? I'm trying to fill a ComboBox whit data from a local AccessDB.

var i : integer;
    x : string;
begin
      with DataModule3.ADOTable1 do begin
         if RecordCount > 0 then
           for i := 1 to RecordCount do begin
             RecNo := i;
             x := FieldByName('Teacher').AsString;
             ComboBox1.Items.Add(x);
           end;
       end;
end;

I have tried lots of things and nothing works, I have tried lots of combobox typed but still doesn't work the only time a combobx showed value was when I selected a row in table then it showed in combobox the rows value by which I need to filter...

2

There are 2 answers

2
RBA On BEST ANSWER

Access Violation is raised most probably because you have forgot to instantiate your datamodule DataModule3. Verify this by calling Assigned function.

1
Zam On
begin
    with DataModule3.ADOTable1 do 
        if Active then
            while not Eof do
                begin
                    ComboBox1.Items.Add(FieldByName('Teacher').AsString);
                    Next;
                end;
end;