Ik heb een MDI applicatie waarbij alle MDI children inheriten van een base class.
Bovendien worden alle menu-selecties, keyboard shortcuts, etc. afgehandeld via Actions.
Werkt prachtig, maar ik stuit op 1 probleem:
Wanneer een gebruiker een MDI form opent, en op [Esc] drukt voordat het form zichtbaar is ([Esc] is gekoppeld aan een Action die eigenlijk alleen maar Close doet in dit geval), dan krijgt 'ie een prachtige Access Violation te zien.
De stack trace geeft dan een hele trits StdWndProc(0,0,0,0) calls te zien, Windows messages naar (nog) niet geinitialiseerde controls denk ik.
Ik heb dit geprobeerd af te vangen in het OnShortCut event van de base class (en daar komt 'ie ook als de error optreedt) door de ComponentState te checken (zie code hieronder).
Maar helaas, op het moment dat de fout optreedt, is de ComponentState leeg...
Enig idee wat ik over het hoofd zie?
Bovendien worden alle menu-selecties, keyboard shortcuts, etc. afgehandeld via Actions.
Werkt prachtig, maar ik stuit op 1 probleem:
Wanneer een gebruiker een MDI form opent, en op [Esc] drukt voordat het form zichtbaar is ([Esc] is gekoppeld aan een Action die eigenlijk alleen maar Close doet in dit geval), dan krijgt 'ie een prachtige Access Violation te zien.
De stack trace geeft dan een hele trits StdWndProc(0,0,0,0) calls te zien, Windows messages naar (nog) niet geinitialiseerde controls denk ik.
Ik heb dit geprobeerd af te vangen in het OnShortCut event van de base class (en daar komt 'ie ook als de error optreedt) door de ComponentState te checken (zie code hieronder).
Maar helaas, op het moment dat de fout optreedt, is de ComponentState leeg...
Enig idee wat ik over het hoofd zie?
Delphi:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| procedure TBaseMDIChild.FormShortCut(var Msg: TWMKey; var Handled: Boolean); var i: Integer; function HandleShortcut(AActionList: TCustomActionList): boolean; var i: integer; ShortCut: TShortCut; ShiftState: TShiftState; begin ShiftState := KeyDataToShiftState(Msg.KeyData); ShortCut := Menus.ShortCut(Msg.CharCode, ShiftState); for i := 0 to AActionList.ActionCount - 1 do if (TCustomAction(AActionList.Actions[i]).Enabled) and (TCustomAction(AActionList.Actions[i]).Visible) and (TCustomAction(AActionList.Actions[i]).ShortCut = ShortCut) then begin Result := TCustomAction(AActionList.Actions[i]).Execute; Exit; end; Result := False; end; begin // don't process keystrokes if the form isn't ready Handled := (ComponentState * [csLoading, csDestroying] <> []); if not Handled then begin if FActionLists <> nil then begin for i := 0 to FActionLists.Count - 1 do begin if HandleShortcut(TCustomActionList(FActionLists[i])) then begin Handled := True; Exit; end; end; end; end; end; |