|
-
Mar 29th, 2024, 09:56 AM
#30
Re: Registry Free Object Instantiation using DirectCOM & RC6
Thanks taishan, glad you like what you see 
Regarding a way to instantiate vbWidgets, there are a few different approaches - all with their upsides and downsides - and I'm not firmly decided on what approach I prefer yet.
Reexre's function is fine, but I have a bit of a natural aversion (rightly or wrongly) to passing the string class name as there's no intellisense and it is easy to make a typo. Granted even a minimal amount of testing would reveal the typo problem, but it just "feels" wrong to me. Reexre's approach also returns an Object, so you don't get the benefit of Intellisense, which can make it a pain to work with.
One advantage for using string class names is that it is easy to use new widget classes as they become available, just start using the new class name. Another advantage is that the code is short and easy to reason about/audit.
In any case, Reexre's code could be written to handle Firehacker's MakeTrue InIde approach with my MRegFree module like so:
Code:
Public Function NewWidget(ClassName As String) As Object
Dim l_InIde As Boolean
#If UseInlineIdeCheck Then
Debug.Assert MakeTrue(l_InIde)
#Else
l_InIde = IsRunningInIde
#End If
If l_InIde Then
' We run in the IDE, so we create the instance from the registered version
Set NewWidget = CreateObject("vbWidgets." & ClassName)
Else
' Not in the IDE, so we create the instance from the registered version
Set NewWidget = New_C.RegFree.GetInstanceEx(PathAppSystem & "vbWidgets.dll", ClassName)
End If
End Function
Another approach is to have single functions for each widget that return a strongly typed widget variable. This is the approach I use in JPBFileFinder. The advantages are that intellisense works, and you can add extra "constructor" parameters that help you get the widget instantiated with things like position and dimensions set without requiring a bunch of extra property lets for everything. The downsides are that you have to update the codebase every time a new Widget is added to vbWidgets, and the code is comparatively quite verbose.
There may be other approaches too - I'm all ears if anyone has any interesting suggestions.
PS: Looking at the MWidgets.bas code in JPBFileFinder, I see that it could use a rewrite to use the new MRegFree module, so I'll see if I can find that time to do that soon.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|