CSV scanner: fix crash when selected filename cannot be opened

This commit is contained in:
Ansgar Becker
2023-10-11 06:42:43 +02:00
parent 62f27dbf0a
commit fa571f72da

View File

@ -125,6 +125,7 @@ begin
Screen.Cursor := crHourGlass; Screen.Cursor := crHourGlass;
btnScan.ImageIndex := 150; btnScan.ImageIndex := 150;
btnScan.Enabled := False; btnScan.Enabled := False;
btnSave.Enabled := False;
// Parse contents to a TGridRows instance // Parse contents to a TGridRows instance
GridRows := TGridRows.Create(True); GridRows := TGridRows.Create(True);
GridRow := nil; GridRow := nil;
@ -144,6 +145,7 @@ begin
InEncl := False; InEncl := False;
try
MainForm.ShowStatusMsg(f_('Reading textfile (%s) ...', [FormatByteNumber(TestChunkSize)])); MainForm.ShowStatusMsg(f_('Reading textfile (%s) ...', [FormatByteNumber(TestChunkSize)]));
Encoding := FLoadDataFrm.FileEncoding; Encoding := FLoadDataFrm.FileEncoding;
OpenTextfile(FLoadDataFrm.editFilename.Text, Stream, Encoding); OpenTextfile(FLoadDataFrm.editFilename.Text, Stream, Encoding);
@ -194,7 +196,11 @@ begin
// Find matching column types for values // Find matching column types for values
Columns := DetectColumnAttributes(GridRows, IgnoreLines); Columns := DetectColumnAttributes(GridRows, IgnoreLines);
SynMemoCreateTable.Text := ComposeCreateStatement(Columns); SynMemoCreateTable.Text := ComposeCreateStatement(Columns);
btnSave.Enabled := True;
except
on E:EFOpenError do
ErrorDialog(E.Message);
end;
GridRows.Free; GridRows.Free;
MainForm.ShowStatusMsg; MainForm.ShowStatusMsg;