@@ -51,6 +51,7 @@ public class DeclarationFinder
51
51
52
52
private Lazy < List < Declaration > > _nonBaseAsType ;
53
53
private Lazy < List < Declaration > > _eventHandlers ;
54
+ private Lazy < List < Declaration > > _controlEventHandlers ;
54
55
private Lazy < List < Declaration > > _projects ;
55
56
private Lazy < List < Declaration > > _classes ;
56
57
@@ -165,6 +166,7 @@ private void InitializeLazyCollections()
165
166
, true ) ;
166
167
167
168
_eventHandlers = new Lazy < List < Declaration > > ( FindAllEventHandlers , true ) ;
169
+ _controlEventHandlers = new Lazy < List < Declaration > > ( FindAllFormControlHandlers , true ) ;
168
170
_projects = new Lazy < List < Declaration > > ( ( ) => DeclarationsWithType ( DeclarationType . Project ) . ToList ( ) , true ) ;
169
171
_classes = new Lazy < List < Declaration > > ( ( ) => DeclarationsWithType ( DeclarationType . ClassModule ) . ToList ( ) , true ) ;
170
172
_handlersByWithEventsField = new Lazy < IDictionary < Declaration , List < Declaration > > > ( FindAllHandlersByWithEventField , true ) ;
@@ -302,6 +304,18 @@ public IEnumerable<Declaration> FindEventHandlers()
302
304
return _eventHandlers . Value ;
303
305
}
304
306
307
+ public IEnumerable < Declaration > FindFormControlEventHandlers ( )
308
+ {
309
+ return _controlEventHandlers . Value ;
310
+ }
311
+
312
+ public IEnumerable < Declaration > FindFormControlEventHandlers ( Declaration control )
313
+ {
314
+ return _eventHandlers . Value
315
+ . Where ( handlers=> handlers . ParentScope == control . ParentScope
316
+ && handlers . IdentifierName . StartsWith ( control . IdentifierName + "_" ) ) ;
317
+ }
318
+
305
319
public IEnumerable < Declaration > Classes => _classes . Value ;
306
320
public IEnumerable < Declaration > Projects => _projects . Value ;
307
321
@@ -1165,15 +1179,15 @@ private IEnumerable<Declaration> FindAllInReferencedProjectByPriority(Declaratio
1165
1179
}
1166
1180
}
1167
1181
1168
- private IEnumerable < Declaration > FindAllFormControlHandlers ( )
1182
+ private List < Declaration > FindAllFormControlHandlers ( )
1169
1183
{
1170
1184
var controls = DeclarationsWithType ( DeclarationType . Control ) ;
1171
1185
var handlerNames = BuiltInDeclarations ( DeclarationType . Event )
1172
1186
. SelectMany ( e => controls . Select ( c => c . IdentifierName + "_" + e . IdentifierName ) )
1173
1187
. ToHashSet ( ) ;
1174
1188
var handlers = UserDeclarations ( DeclarationType . Procedure )
1175
1189
. Where ( procedure => handlerNames . Contains ( procedure . IdentifierName ) ) ;
1176
- return handlers ;
1190
+ return handlers . ToList ( ) ;
1177
1191
}
1178
1192
1179
1193
private List < Declaration > FindAllEventHandlers ( )
@@ -1197,7 +1211,7 @@ private List<Declaration> FindAllEventHandlers()
1197
1211
. Where ( item => handlerNames . Contains ( item . IdentifierName ) )
1198
1212
)
1199
1213
. Concat ( _handlersByWithEventsField . Value . AllValues ( ) )
1200
- . Concat ( FindAllFormControlHandlers ( ) ) ;
1214
+ . Concat ( FindFormControlEventHandlers ( ) ) ;
1201
1215
return handlers . ToList ( ) ;
1202
1216
1203
1217
// Local functions to help break up the complex logic in finding built-in handlers
0 commit comments