Een goede grap mag vrienden kosten.
Ik ga mijn vraag zelf beantwoorden
. Je blijkt acties te kunnen registeren via de RegisterActions procedure in de unit ActnList. Klinkt eenvoudig, totdat je in de helpfiles de summiere uitleg bij de laatste functieparameter leest. Dan blijk je opeens nog 100+ regels aan extra code te moeten schrijven.
Een goede grap mag vrienden kosten.
Verwijderd
Toen TAction werd geintroduceerd (Delphi 5 geloof ik? Delphi 4 heb ik overgeslagen) kwamen mensen als Ray Konopka en Mark Miller met dezelfde kritiek. Actions zijn mooi, maar voor bv. een component maker (en dat zijn die 2 jongens) is 't een ramp als je een custom action wilt registreren.
Jammer dat Borland daar nu (Delphi 2005) nog steeds niet een handige IDE API voor heeft ontwikkeld...
Jammer dat Borland daar nu (Delphi 2005) nog steeds niet een handige IDE API voor heeft ontwikkeld...
IDE API in Delphi 2005 is toch zo brak (zie QC), dat het niet echt serieus te nemen is.
[ Voor 5% gewijzigd door alienfruit op 30-04-2005 22:37 ]
Verwijderd
Define "brak", en wat is QC?
Ik ben zelf ook niet blij met de nieuwe VS.NET IDE, maar da's meer een kwestie van wennen.
Ik ben zelf ook niet blij met de nieuwe VS.NET IDE, maar da's meer een kwestie van wennen.
Nu ik weer terug ben van vakantie heb ik vandaag de code in elkaar gezet.
De code om mijn acties te registreren:
TDBEditCut, TDBEditCopy, TDBEditPaste, TDBEditUndo en TDBEditDelete zijn actions die zijn gedefinieerd in de unit DBEditActns. Het zijn data-aware varianten van TEditCut etcetera en houden er rekening mee dat een edit control read-only kan zijn. Source code inclusief design-time package
De code om mijn acties te registreren:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| {------------------------------------------------------------------------------- Design-time support for data-aware edit actions in the DBEditActns unit Copyright (c) 2005 Robin Gerrets. All rights reserved. -------------------------------------------------------------------------------} unit DBEditActnsReg; interface uses Classes, ActnList, ActnRes, StdActns, DBEditActns; type TActionTemplate = record ActionClass: TBasicActionClass; TemplateClass: TBasicActionClass; end; TInheritedActions = class(TStandardActions) private function FindTemplateInstance(TemplateClass: TBasicActionClass): TBasicAction; protected procedure ConstructActions(ActionTemplates: array of TActionTemplate); end; procedure Register; implementation type TDBEditActions = class(TInheritedActions) public constructor Create(AOwner: TComponent); override; end; { TInheritedActions } function TInheritedActions.FindTemplateInstance(TemplateClass: TBasicActionClass): TBasicAction; var i: Integer; begin Result := nil; for i := 0 to ComponentCount - 1 do if Components[i].ClassType = TemplateClass then begin Result := TAction(Components[i]); Break; end; end; procedure TInheritedActions.ConstructActions(ActionTemplates: array of TActionTemplate); var i: Integer; Action, Template: TBasicAction; begin for i := Low(ActionTemplates) to High(ActionTemplates) do begin Template := FindTemplateInstance(ActionTemplates[i].TemplateClass); Action := ActionTemplates[i].ActionClass.Create(Self); if Assigned(Template) and (Template is TCustomAction) and (Action is TCustomAction) then begin TCustomAction(Action).Caption := TCustomAction(Template).Caption; TCustomAction(Action).Hint := TCustomAction(Action).Hint; TCustomAction(Action).ImageIndex := TCustomAction(Action).ImageIndex; TCustomAction(Action).ShortCut := TCustomAction(Action).ShortCut; end; end; end; { TDBEditActions } constructor TDBEditActions.Create(AOwner: TComponent); const Templates: array[0..4] of TActionTemplate = ( (ActionClass: TDBEditCut; TemplateClass: TEditCut), (ActionClass: TDBEditCopy; TemplateClass: TEditCopy), (ActionClass: TDBEditPaste; TemplateClass: TEditPaste), (ActionClass: TDBEditUndo; TemplateClass: TEditUndo), (ActionClass: TDBEditDelete; TemplateClass: TEditDelete)); begin inherited; ConstructActions(Templates); end; procedure Register; begin RegisterActions('Edit', [TDBEditCut, TDBEditCopy, TDBEditPaste, TDBEditUndo, TDBEditDelete], TDBEditActions); end; end. |
TDBEditCut, TDBEditCopy, TDBEditPaste, TDBEditUndo en TDBEditDelete zijn actions die zijn gedefinieerd in de unit DBEditActns. Het zijn data-aware varianten van TEditCut etcetera en houden er rekening mee dat een edit control read-only kan zijn. Source code inclusief design-time package
Een goede grap mag vrienden kosten.
Verwijderd
In de code zie ik staan:
TCustomAction(Action).Hint := TCustomAction(Template).Hint; Ipv
TCustomAction(Action).Hint := TCustomAction(Action).Hint;
Nu gebeurt zo te zien niets
Of mis ik iets?
Delphi:
In de eerste regel wordt het template naar de nieuwe action gecopieerd. Moet dat in regel 2-4 ook niet gebeuren? Dus: 1
2
3
4
| TCustomAction(Action).Caption := TCustomAction(Template).Caption; TCustomAction(Action).Hint := TCustomAction(Action).Hint; TCustomAction(Action).ImageIndex := TCustomAction(Action).ImageIndex; TCustomAction(Action).ShortCut := TCustomAction(Action).ShortCut; |
TCustomAction(Action).Hint := TCustomAction(Template).Hint; Ipv
TCustomAction(Action).Hint := TCustomAction(Action).Hint;
Nu gebeurt zo te zien niets
Nee, die zie je helemaal goed
. Bedankt voor de tip. Sterker nog, nu ik nog eens zit te klooien merk ik dat de ImageIndex wel netjes wordt meegekopieerd, maar de bijbehorende glyph niet. Het lijkt erop dat Delphi intern wat trucjes uithaalt, waardoor alleen bij de reeds in Delphi aanwezige standard actions een glyph wordt gekopieerd naar de ImageList. Vaag.
Delphi:
67
68
69
70
71
72
73
74
| if Assigned(Template) and (Template is TCustomAction) and (Action is TCustomAction) then begin TCustomAction(Action).Caption := TCustomAction(Template).Caption; TCustomAction(Action).Hint := TCustomAction(Template).Hint; // TCustomAction(Action).ImageIndex := TCustomAction(Template).ImageIndex; TCustomAction(Action).ShortCut := TCustomAction(Template).ShortCut; end; |
Een goede grap mag vrienden kosten.
Pagina: 1