문제
데 VB 코드(실제로 VBA)는 기본적으로 제외하고는 동일한 유형에서는 다하고 있습니다.이후 나는 생각하는 건조한 원리가 좋은지도 원리를 위한 소프트웨어 개발을 쓰고 싶어 하나의 일상에 대한 다른 모든 종류 할 필요가에서 운영하.예를 들면 나는 두 개의 조각의 코드가 이와 같은:
Dim i as Obj1
Set i = RoutineThatReturnsObj1()
i.property = newvalue
Dim i as Obj2
Set i = RoutineThatReturnsObj2()
i.property = newvalue
내가 좋아하는 이 같은 모두를 처리하기 위해 인스턴스:
Sub MyRoutine(o as ObjectType, r as RoutineToInitializeObject, newvalue as value)
Dim i as o
Set i = r
i.property = newvalue
End Sub
사용한 경우 C++나를 생성하는 템플릿과에 대해서는 더 이상 말하지 않습니다.그러나 나를 사용하여 VBA.나는 매우는 없는 기능을 다음과 같 C++템플릿에서 VBA 어의 정의가 다른 어떤 의미는 수도 동일한 효과를 얻을?나의 답변은 없지만 여기기 때문에 어쩌면 몇 가지 기능의 VBA 했다.
해결책
에 아무것도 없 VB6 는 것입니다.한 경우 업데이트를 Visual Studio 도구를 함께 사무실.Net 사용할 수 있습 generics:
Function MyRoutine(Of O)(R As Delegate, newvalue As Object) As O
Dim i As O = CType(r.Method.Invoke(Nothing, Nothing), O)
'you need another parameter to tell it which property to use'
' and then use reflection to set the value'
i.property = newvalue
return i
End Function
제휴하지 않습니다 StackOverflow