Skip to content

Commit 83c4947

Browse files
committed
fix: crash when opening textfile import dialog, with 0 tables in database
Refs #2556
1 parent f0d7103 commit 83c4947

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
@@ -232,23 +232,24 @@ procedure Tloaddataform.comboDatabaseChange(Sender: TObject);
232232

233233
procedure Tloaddataform.comboTablePopulate(SelectTableName: String; RefreshDbObjects: Boolean);
234234
var
235-
count, i: Integer;
235+
i: Integer;
236236
DBObjects: TDBObjectList;
237-
seldb, seltable: String;
237+
FocusedTable: String;
238238
begin
239239
// read tables from db
240240
comboTable.Items.Clear;
241-
seldb := Mainform.ActiveDatabase;
242-
seltable := Mainform.ActiveDbObj.Name;
241+
FocusedTable := Mainform.ActiveDbObj.Name;
243242
DBObjects := FConnection.GetDBObjects(comboDatabase.Text, RefreshDbObjects);
244243
for i:=0 to DBObjects.Count-1 do begin
245244
if DBObjects[i].NodeType in [lntTable, lntView] then
246245
comboTable.Items.Add(DBObjects[i].Name);
247-
count := comboTable.Items.Count-1;
248-
if SelectTableName.IsEmpty and (comboDatabase.Text = seldb) and (comboTable.Items[count] = seltable) then
249-
comboTable.ItemIndex := count
250-
else if (not SelectTableName.IsEmpty) and (SelectTableName = comboTable.Items[count]) then
251-
comboTable.ItemIndex := count;
246+
end;
247+
248+
if comboDatabase.Text = Mainform.ActiveDatabase then begin
249+
if not SelectTableName.IsEmpty then
250+
comboTable.ItemIndex := comboTable.Items.IndexOf(SelectTableName)
251+
else if not FocusedTable.IsEmpty then
252+
comboTable.ItemIndex := comboTable.Items.IndexOf(FocusedTable);
252253
end;
253254
if (comboTable.ItemIndex = -1) and (comboTable.Items.Count >= 1) then
254255
comboTable.ItemIndex := 0; // First real table

0 commit comments

Comments
 (0)