help me in this vba code implementing class loader and abstract in concept in vba.
file classloaderandfactory
Option Compare Database
Implements IClassLoaderAndFactory
Private Function IClassLoaderAndFactory_findtheattributeaspectforfieldinjectionresource(m_codemodule As VBIDE.CodeModule) As Variant
End Function
'loading class into memory with injection / configuraiton if needed there is passing of
'interface for the second parameter for temporary easy vba programming. if not maybe have to use
'code search (probalby maybe)
Private Function IClassLoaderAndFactory_load(theclass As String, m_theabstractobject As Object) As Variant
Dim a As VBE
Dim b As CodeModule
Set a = Application.VBE
'find all resource attribute aspect
Dim m_theobject As Object
Dim m_tempassociateobject As Object
m_theobject = CreateInstance(theclass)
Set b = a.ActiveVBProject.VBComponents.Item(theclass).CodeModule
For I = 1 To a.ActiveVBProject.VBComponents.Item(theclass).CodeModule.Lines
If Len(b.Lines(I, 1) > 0) Then
If InStr("", b.Lines(I, 1), "'@resource") > 0 Then
'fouund it
'get next line
'is it
If InStr("", b.Lines(I + 1, 1), "dim") > 0 Or InStr("", b.Lines(I + 1, 1), "PRIVATE WITHEVENTS") > 0 Then
'IS THIS property?
Dim tempobject As Object
temparray = Split(b.Lines(I, 1), " ")
Set tempobject = IClassLoaderAndFactory_load(temparray(1), m_theabstractobject)
Set m_theabstractobject.Properties("temparray(1)") = tempobject
'todo:what if not properties
End If
End If
Next
'found? if not loadconfigutraiton
End Function
Private Function IClassLoaderAndFactory_loadclassconfiguration(configurationfile As String) As Variant
End Function
file:iclassloaderandfactory
Option Compare Database
Public Function load(theclass As String, m_theabstractobject As Object)
End Function
Public Function loadclassconfiguration(configurationfile As String)
End Function
Public Function findtheattributeaspectforfieldinjectionresource(m_codemodule As CodeModule)
End Function
file:generalmodulewithmetacache(only simply implemented)
Public Function LazilyCreateMPCache()
LazilyCreateMPCache = Application.VBE.ActiveVBProject.VBComponents("Module2")
End Function
Public Function FunctionExists(m_typename As String, m_module As VBComponent)
FunctionExists = m_module.CodeModule.Find(m_typename, 1, 1, -1, -1, False, False, False)
End Function
Public Function CreateInstance(typeName As String) As Object
Dim module As VBComponent
Set module = LazilyCreateMPCache()
If Not FunctionExists(typeName, module) Then
Call AddInstanceCreationHelper(typeName, module)
End If
Dim instanceCreationHelperName As String
instanceCreationHelperName = module.Name & ".GetInstanceOf" & typeName
Set CreateInstance = Application.Run(instanceCreationHelperName)
End Function
Sub AddInstanceCreationHelper(typeName As String, module As VBComponent)
Dim strCode As String
strCode = _
"Public Function GetInstanceOf" & typeName & "() As " & typeName & vbCrLf & _
"Set GetInstanceOf" & typeName & " = New " & typeName & vbCrLf & _
"End Function"
Call AddFunction(strCode, module)
End Sub
Public Sub AddFunction(m_strcode As String, m_module As VBComponent)
m_module.CodeModule.AddFromString m_strcode
End Sub
can anyone advise me on my approach doing this? thxs in advance
Aucun commentaire:
Enregistrer un commentaire