Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Offene TDBLookupComboBox verursaxht Exception bei ESC-Taste (https://www.delphipraxis.net/192571-offene-tdblookupcombobox-verursaxht-exception-bei-esc-taste.html)

SneakL8 1. Mai 2017 18:48

Offene TDBLookupComboBox verursaxht Exception bei ESC-Taste
 
Hallo zusammen,

ich habe einen modalen Dialog mit "Abbrechen"-Button mit Cancel-Eigenschaft. Auf diesem Dialog befindet sich eine TDBLookupComboBox. Wenn ich diese zur Laufzeit aufklappe und dann die Esc-Taste drücke, erhalte ich eine EInvalidOperation-Exception "Ein deaktiviertes oder unsichtbares Fenster kann nicht den Fokus erhalten.".

Anbei der CallStack:
00511a19 +059 TG.exe Forms 4782 +4 TCustomForm.SetFocus
0050f94e +02e TG.exe Forms 3803 +3 TCustomForm.FocusControl
004f5850 +020 TG.exe Controls 7779 +3 TWinControl.SetFocus
00558663 +04f TG.exe DBCtrls 5146 +4 TDBLookupComboBox.CloseUp
0055967e +01e TG.exe DBCtrls 5509 +2 TDBLookupComboBox.WMKillFocus
004eeaa3 +1df TG.exe Controls 4645 +53 TControl.WndProc
004f27d2 +18e TG.exe Controls 6342 +33 TWinControl.WndProc
004f23a4 +034 TG.exe Controls 6237 +3 TWinControl.MainWndProc
0048bfe0 +014 TG.exe Classes 10966 +8 StdWndProc
775a8e54 +034 ntdll.dll KiUserCallbackDispatcher
0050fcc3 +03f TG.exe Forms 3891 +4 TCustomForm.SetWindowFocus
0050fd74 +080 TG.exe Forms 3906 +9 TCustomForm.SetActive
00510747 +02f TG.exe Forms 4168 +2 TCustomForm.WMActivate
004eeaa3 +1df TG.exe Controls 4645 +53 TControl.WndProc
004f27d2 +18e TG.exe Controls 6342 +33 TWinControl.WndProc
0050ddb8 +478 TG.exe Forms 3098 +103 TCustomForm.WndProc
004f23a4 +034 TG.exe Controls 6237 +3 TWinControl.MainWndProc
0048bfe0 +014 TG.exe Classes 10966 +8 StdWndProc
775a8e54 +034 ntdll.dll KiUserCallbackDispatcher
00511cef +283 TG.exe Forms 4843 +44 TCustomForm.ShowModal
005f7e78 +02c TG.exe UpdateForm 244 +4 TUpdForm.ShowModal
006605f7 +037 TG.exe TGStandard 711 +15 TTGStandardForm.ShowModal
00660248 +778 TG.exe TGStandard 662 +181 TTGStandardForm.CreateEx
0065fa7e +08a TG.exe TGStandard 460 +2 TTGStandardForm.Create
0066521b +04f TG.exe TGStandard 2201 +5 TTGStandardForm.CreateEditDlg
006653eb +05b TG.exe TGStandard 2236 +7 TTGStandardForm.DoKorr
0065d9f8 +020 TG.exe TGMain 2250 +3 TTGMainForm.KorrActionExecute
0048b085 +01d TG.exe Classes 10464 +3 TBasicAction.Execute
[...]

Nach einigen Tasts und Analyse sieht es für mich so aus als wenn die Esc-Taste durch den Cancel-Button zuerst das modale Formular schließt und danach die TDBLookupComboBox, ihre Auswahlliste und dabei den Focus an das modale Fenster zurückgeben will (Form.SetFocus), das aber gerade schon geschlossen wurde.

Ich hab schon geschaut, ob ich da irgendwetwas falsch mache, bin aber derzeit keine Schuld bewusst. :roll: Ist das evtl. ein Fehlverhalten der DBLookupComboBox? Tante Googlelieft mir dafür aber leider keine Anhaltspunkte.

Habt Ihr einen Tipp für mich?

Das passiert unter Delphi 7.01 (ich weiß, ist alt...).

Viele Grüße
Sneak-L8

Papaschlumpf73 2. Mai 2017 11:44

AW: Offene TDBLookupComboBox verursaxht Exception bei ESC-Taste
 
Das hatte ich auch schon mal, bin aber zu faul solchen Fehlern auf den Grund zu gehen. Das hier hilft jedenfalls:

Delphi-Quellcode:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if DBLookupComboBox1.ListVisible then
 begin
 DBLookupComboBox1.CloseUp(true);
 Abort;
 end;
end;

SneakL8 2. Mai 2017 21:30

AW: Offene TDBLookupComboBox verursaxht Exception bei ESC-Taste
 
Hallo Papaschlumpf73,

super, hab die FormClose-Methode meines zentralen Form-Vorfahrens erweitert und suche zunächst nach einer "offenen" DBLookupComboBox und schließe diese. Mache dann aber ein Action = caNone anstelle des Aborts, aber das ist vermutlich Geschmacksache.

Auf jeden Fall wird mit Esc nun nur noch die ComboBox geschlossen und erst beim zweiten Esc das Formular. Und vor allem ist die EInvalidOperation weg!

Vielen Dank!
Sneak-L8


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz