Skip to content

Commit 03c005a

Browse files
committed
fix: crash when opening textfile import dialog, with 0 tables in database
Refs #2556
1 parent fc222fb commit 03c005a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

source/loaddata.pas

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,24 @@ procedure Tloaddataform.comboDatabaseChange(Sender: TObject);
229229

230230
procedure Tloaddataform.comboTablePopulate(SelectTableName: String; RefreshDbObjects: Boolean);
231231
var
232-
count, i: Integer;
232+
i: Integer;
233233
DBObjects: TDBObjectList;
234-
seldb, seltable: String;
234+
FocusedTable: String;
235235
begin
236236
// read tables from db
237237
comboTable.Items.Clear;
238-
seldb := Mainform.ActiveDatabase;
239-
seltable := Mainform.ActiveDbObj.Name;
238+
FocusedTable := Mainform.ActiveDbObj.Name;
240239
DBObjects := FConnection.GetDBObjects(comboDatabase.Text, RefreshDbObjects);
241240
for i:=0 to DBObjects.Count-1 do begin
242241
if DBObjects[i].NodeType in [lntTable, lntView] then
243242
comboTable.Items.Add(DBObjects[i].Name);
244-
count := comboTable.Items.Count-1;
245-
if SelectTableName.IsEmpty and (comboDatabase.Text = seldb) and (comboTable.Items[count] = seltable) then
246-
comboTable.ItemIndex := count
247-
else if (not SelectTableName.IsEmpty) and (SelectTableName = comboTable.Items[count]) then
248-
comboTable.ItemIndex := count;
243+
end;
244+
245+
if comboDatabase.Text = Mainform.ActiveDatabase then begin
246+
if not SelectTableName.IsEmpty then
247+
comboTable.ItemIndex := comboTable.Items.IndexOf(SelectTableName)
248+
else if not FocusedTable.IsEmpty then
249+
comboTable.ItemIndex := comboTable.Items.IndexOf(FocusedTable);
249250
end;
250251
if (comboTable.ItemIndex = -1) and (comboTable.Items.Count >= 1) then
251252
comboTable.ItemIndex := 0; // First real table

0 commit comments

Comments
 (0)