Autor Beitrag
Natti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mo 15.10.07 11:10 
Hallo,

ich habe folgendes Problem. Beim Formularschliessen wird beim OnCloseQuery abgefragt, welches Status die Datenmenge hat. Und wenn der Satz "State in [dsEdit,dsInsert]" hat, dann wird der Datensatz gespeichert. Es funktioniert nur, wenn ich Formular beim Klicken auf das Kreuzchen schliesse. Wenn ich mit ESC raus gehe, dann State=dsBrowse. (obwohl ich genau weis, dass der Satz noch nicht gespeichert ist, und man kann es eindeutig in DBGrid sehen)
Und dann wird der Datensatz nicht gespeichert.
Es soll doch keine Unterschiede geben, ob ich aufs Kreuzchen klicke oder ESC-Taste drucke?!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm_sortiment.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=vk_escape then Close;
end;

procedure TForm_sortiment.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
if xtab.State in [dsInsert, dsEdit] then
begin
   if messagedlg('Sie haben Daten nicht gespeichert!'+chr(13)+'Jetzt speichern?',mtConfirmation,[mbyes,mbno],0)=mryes then
      xtab.Post
   else
   if xtab.state=dsedit then
      xtab.cancel
   else
      xtab.delete; 
end;
xtab.close;
release;
end;
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 15.10.07 14:30 
Wurde das FormCloseQuery etwa von sonstwoher einfach kopiert ? Ist das im OI zu sehen ? Ansonsten weiß nämlich die DFM überhaupt nichts von dem Code und ignoriert ihn. Würde das Verhalten erklären. Das nächste wäre, mal nach KeyPreview zu gucken.

_________________
Gruß
Hansa
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 15.10.07 15:49 
Vermutlich führt Dein <ESC> automatisch ein Cancel der DB-Operation aus. Daher solltest Du noch den Tipp mit dem KeyPreview von user profile iconHansa beachten. Wenn dem nämlich so ist, reagiert Dein Programm völlig normal, da Dein DataSet im Modus dsBrowse ist (durch Dein <ESC>).
Natti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mo 15.10.07 16:19 
Danke für die Antwort. Ich vermute es auch, dass irgendwie im Hintergrund dataset in dsBrowse versetzt wird. Ich habe statt ESC mit anderen Tasten probiert und es funktioniert, nur mit ESC nicht. Kann es irgendwelche Einstellung der Tabelle sein (Paradox), dass so eine Reaktion auf die ESC-Taste folgt?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 15.10.07 16:34 
Du kannst in der Form die Eigenschaft KeyPreview auf True stellen. Evtl funktioniert es dann auch mit <ESC>.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 15.10.07 20:33 
user profile iconNatti hat folgendes geschrieben:
Danke für die Antwort...


Das ist toll. :lol: Nur, wo bleiben die Antworten auf die von mir gestellten Fragen ? Deshalb nochmals :

user profile iconhansa hat folgendes geschrieben:
Wurde das FormCloseQuery etwa von sonstwoher einfach kopiert ? Ist das im OI zu sehen ? Ansonsten weiß nämlich die DFM überhaupt nichts von dem Code und ignoriert ihn. Würde das Verhalten erklären. Das nächste wäre, mal nach KeyPreview zu gucken.


Das KeyPreview rangiert dabei erst an 2. Stelle ! Entweder jetzt Antwort darauf und zwar genau oder eben nicht. ESC ist eine Funktionstaste. Eine nicht bekanntgegebene "andere Taste" eventuell aber nicht. Die Auswirkungen wären dann eher im OnKeyPress-Ereignis zu vermuten, sofern nicht auch kopiert.

_________________
Gruß
Hansa
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 16.10.07 08:00 
@Hansa:

Wäre es ein C&P-Problem, wie von Dir beschrieben, dann dürfte die Methode in keinem Fall aufgerufen werden. Auch nicht, wenn man das Kreuz anklickt. Frage beantwortet?
Natti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Di 16.10.07 10:09 
FormCloseQuery wurde nicht von sonstwoher kopiert. Die wird auch ausgeführt. Nur xtab.state=dsBrowse, wenn man mit ESC rausgeht. Ich habe mit z.B. F2 probiert, ist auch eine Funktionstaste, aber es hat funktioniert.
KeyPreview auf TRUE zu setzen hat auch nicht geholfen.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 16.10.07 14:15 
user profile iconjasocul hat folgendes geschrieben:
@Hansa:

..Frage beantwortet?


Ne. Kreuz schließt die Form und Basta. :mrgreen: D.h. FormCloseQuery wird aufgerufen. Bei ESC ist nicht unbedingt gesagt, dass das im FormCloseQuery landet, sofern die DFM nichts von dem OnKeyDown mitkriegt. Könnte einfach so dahin kopiert worden sein. Z.B. aus der Hilfe.

Zum Thema an sich : klicke im OI das Ereignis OnKeyDown doppelt an und guck, wo du im Quelltext landest. Könnte wetten, dass das nicht da ist, wo in der Nähe Close aufgerufen wird. Kann mich aber auch täuschen. :lol:

_________________
Gruß
Hansa