Prev: Fast way to delete files
Next: 'MappingInfo
From: Schmidt on 23 Oct 2009 08:12 "Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag news:44ED8D2F-0B50-418F-95F4-E17A02CB4AB4(a)microsoft.com... > As was previouly mentoned in a post to consider a "Factory" > So now what about Factories? Factories are often used as a mere instantiation-helper for different kinds of classes ('Nobody' already gave you an example for that). So, instead of writing: Set oMyClass = New cMyClass oMyClass.Prop1 = "abc" 'initialize a property oMyClass.Prop2 = 123 'initialize another property you could do all that in one line, using a Factory: Set oMyClass = Factory.NewMyClass("abc", 123) So, the brought up "factory-class" is just a pattern, how to work in a comfortable way with multiple (child)Class- instances. Factories are not only used for creation, they can also be used for "hosting" - and even for "hosting and event-aggregation" as in your special case. If you want a centralized Aggregation of a group of possible "event-raisers", you need two "extra-classes" in your "event-consumer-project" (one of these classes is the Factory - and the other additional class is a small "event-wrapper-instance". So, in your scenario you have (will need): cAxExeThread ... (your ThreadClass in the AX-Exe-project) cEvtWrapper ...(a private Class in your normal project) cFactory ...(a private Class in your normal project) Currently you are doing this (with only cAxExeThread): '** presumably in a Form Private WithEvents oAxExeThread As cAxExeThread Private Sub Form_Load() Set oAxExeThread = New cAxExeThread End Sub Now, if you want something like an "Object-instance- Array", which is able to raise "aggregated events", you can do that with the already mentioned "two extra-classes". In cEvtWrapper: '** this is now the threadclass-host, able to receive its events Option Explicit Private WithEvents oAxExeThread As cAxExeThread Private Dispatcher as cFactory 'we hold a reference to the factory here Friend Sub Init(F as cFactory) 'the init-procedure, called from cFactory Set Dispatcher = F 'just keep the Factory-reference in 'Dispatcher' Set oAxExeThread = New cAxExeThread 'and create the Thread-instance End Sub Private Sub oAxExeThread_SomeEvent() 'this is the normal Thread-EventProc Dim EventName As String EventName = "SomeEvent" Dispatcher.DelegateEventFor oAxExeThread, EventName End Sub Now in cFactory: Option Explicit Event ThreadEventOn(oThread as cAxExeThread, EventName$) Public Col as New Collection 'we just store all the cEvtWrappers here Public Sub AddThread() 'this creates and adds a new Thread Dim oEvtWrapper as cEvtWrapper Set oEvtWrapper = New cEvtWrapper 'create a new wrapper... oEvtWrapper.Init Me '...and indirectly a thread inside the wrapper Col.Add oEvtWrapper 'finally we keep a reference in mCol End Sub Friend Sub DelegateEventFor(oThread as cAxExeThread, EventName$) RaiseEvent ThreadEventOn(oThread, EventName) End Sub Public Sub CleanUp() Set Col = Nothing End Sub Not that many lines of code till here, it's more the indirections which can cause "some confusion" at the first sight. Also, the above is just air-code - please adapt it appropriately to your needs first. But with these two classes, you can now write in your Form: Private WithEvents oFactory as cFactory Private Sub Form_Load() dim i& Set oFactory = New cFactory For i = 1 to N oFactory.AddThread Next i End Sub Sub oFactory_ThreadEventOn(oThread as cAxExeThread, EventName$) 'here you will receive the Events from all added threads, 'oThread specifies the Thread-instance the Event in question 'was raised from End Sub Private Sub Form_UnLoad() oFactory.CleanUp End Sub Olaf
From: Bee on 23 Oct 2009 11:01 big thanks. I will study this and try to implement it. now I have something to sink my teeth into. "Schmidt" wrote: > > "Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag > news:44ED8D2F-0B50-418F-95F4-E17A02CB4AB4(a)microsoft.com... > > > As was previouly mentoned in a post to consider a "Factory" > > So now what about Factories? > > Factories are often used as a mere instantiation-helper > for different kinds of classes ('Nobody' already gave you > an example for that). > > So, instead of writing: > Set oMyClass = New cMyClass > oMyClass.Prop1 = "abc" 'initialize a property > oMyClass.Prop2 = 123 'initialize another property > > you could do all that in one line, using a Factory: > Set oMyClass = Factory.NewMyClass("abc", 123) > > So, the brought up "factory-class" is just a pattern, how > to work in a comfortable way with multiple (child)Class- > instances. > Factories are not only used for creation, they can also > be used for "hosting" - and even for "hosting and > event-aggregation" as in your special case. > > If you want a centralized Aggregation of a group of > possible "event-raisers", you need two "extra-classes" > in your "event-consumer-project" (one of these classes > is the Factory - and the other additional class is a small > "event-wrapper-instance". > > So, in your scenario you have (will need): > > cAxExeThread ... (your ThreadClass in the AX-Exe-project) > cEvtWrapper ...(a private Class in your normal project) > cFactory ...(a private Class in your normal project) > > > Currently you are doing this (with only cAxExeThread): > '** presumably in a Form > Private WithEvents oAxExeThread As cAxExeThread > Private Sub Form_Load() > Set oAxExeThread = New cAxExeThread > End Sub > > > Now, if you want something like an "Object-instance- > Array", which is able to raise "aggregated events", you > can do that with the already mentioned "two extra-classes". > > In cEvtWrapper: > '** this is now the threadclass-host, able to receive its events > Option Explicit > > Private WithEvents oAxExeThread As cAxExeThread > Private Dispatcher as cFactory 'we hold a reference to the factory here > > Friend Sub Init(F as cFactory) 'the init-procedure, called from cFactory > Set Dispatcher = F 'just keep the Factory-reference in 'Dispatcher' > Set oAxExeThread = New cAxExeThread 'and create the Thread-instance > End Sub > > Private Sub oAxExeThread_SomeEvent() 'this is the normal Thread-EventProc > Dim EventName As String > EventName = "SomeEvent" > Dispatcher.DelegateEventFor oAxExeThread, EventName > End Sub > > Now in cFactory: > Option Explicit > > Event ThreadEventOn(oThread as cAxExeThread, EventName$) > > Public Col as New Collection 'we just store all the cEvtWrappers here > > Public Sub AddThread() 'this creates and adds a new Thread > Dim oEvtWrapper as cEvtWrapper > Set oEvtWrapper = New cEvtWrapper 'create a new wrapper... > oEvtWrapper.Init Me '...and indirectly a thread inside the wrapper > Col.Add oEvtWrapper 'finally we keep a reference in mCol > End Sub > > Friend Sub DelegateEventFor(oThread as cAxExeThread, EventName$) > RaiseEvent ThreadEventOn(oThread, EventName) > End Sub > > Public Sub CleanUp() > Set Col = Nothing > End Sub > > > Not that many lines of code till here, it's more the indirections > which can cause "some confusion" at the first sight. > Also, the above is just air-code - please adapt it appropriately > to your needs first. > > But with these two classes, you can now write in your Form: > > Private WithEvents oFactory as cFactory > > Private Sub Form_Load() > dim i& > Set oFactory = New cFactory > For i = 1 to N > oFactory.AddThread > Next i > End Sub > > Sub oFactory_ThreadEventOn(oThread as cAxExeThread, EventName$) > 'here you will receive the Events from all added threads, > 'oThread specifies the Thread-instance the Event in question > 'was raised from > End Sub > > Private Sub Form_UnLoad() > oFactory.CleanUp > End Sub > > Olaf > > > . >
From: Bee on 23 Oct 2009 11:06 why? well because that is how i first learned to access this newsgtroup. I have Windows Live Mail that has newsreader. BUT it to is missing posts too. So maybe you too are missing posts. Yesterday I say your post in Google and not in MS. I posted in MS and a few minutes later your post showed up there. Strange that posts appear in google before MS but then I guess that depends on where you post. thanks for all your help. "mayayana" wrote: > Also, why are you going to "Microsoft Communites"? > It's a crappy web interface that requires javascript. > Ditto for Google. Why not just use a decent newsreader > and tune to the NNTP server? > > I get a kick out of the MS communities website. I never > enable javascript, and if I go to one of their links it gives > me a blank page with big red letters saying that it won't > work without javascript. But that's *after* the page is loaded. > If I stop the page load at just the right moment I can see > the posts just fine. :) > > > . >
From: mayayana on 23 Oct 2009 14:20 > why? well because that is how i first learned to access this newsgtroup. > I have Windows Live Mail that has newsreader. I've never used Windows Mail. Is that the same as Windows Live Mail? I thought it was just Vista's renamed Outlook Express. In any case, what everyone is talking about is that newsgroups have their own protocol. Outlook Express, Thunderbird (I think) and various 3rd-party programs allow you to read groups by connecting directly to the NNTP server. You then get them in a plain text format that you can read like email, except that each email item has links to any responses posted. It's a much easier, faster, clearer way to read groups than using Google or "Microsoft Communites". Those sites are taking the newsgroup content and putting it in webpage format, which it was never well-suited to. There are also a lot of private sites that simply collect the newsgroup posts and put them online as though they were a private forum. (I've often found my own posts co-opted by such sites, with me listed with the status of "Guest" because I haven't become a member of that particular site. :) I don't understand how the web-based forums like Google groups started in the first place. I can only guess that -- perhaps like you -- a lot of people simply don't know that they can access newsgroups directly.
From: Bee on 25 Oct 2009 17:21
I follow what you wrote. I see how I can pass initial parameters when the class is instantiated. But I do not understand how to do this type of interface after using the suggested collection. I do not know how to reference the class through the factory. oMyClass.Prop1 = "abc" ' set a parameter In my scenario, I need to provide some parameters at initialization, then provide a few parameters as the ActiveX EXE is running and also receive a few events. I see that two out of three can be accomplished, just not the parameter passing while running. Also, each ActiveX EXE will receive different parameters while running so I need a reference to each as they are created that I can later use to indicate which is receiving a unique parameter. Thanks for the help so far. Just a little more please. "Schmidt" wrote: > > "Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag > news:44ED8D2F-0B50-418F-95F4-E17A02CB4AB4(a)microsoft.com... > > > As was previouly mentoned in a post to consider a "Factory" > > So now what about Factories? > > Factories are often used as a mere instantiation-helper > for different kinds of classes ('Nobody' already gave you > an example for that). > > So, instead of writing: > Set oMyClass = New cMyClass > oMyClass.Prop1 = "abc" 'initialize a property > oMyClass.Prop2 = 123 'initialize another property > > you could do all that in one line, using a Factory: > Set oMyClass = Factory.NewMyClass("abc", 123) > > So, the brought up "factory-class" is just a pattern, how > to work in a comfortable way with multiple (child)Class- > instances. > Factories are not only used for creation, they can also > be used for "hosting" - and even for "hosting and > event-aggregation" as in your special case. > > If you want a centralized Aggregation of a group of > possible "event-raisers", you need two "extra-classes" > in your "event-consumer-project" (one of these classes > is the Factory - and the other additional class is a small > "event-wrapper-instance". > > So, in your scenario you have (will need): > > cAxExeThread ... (your ThreadClass in the AX-Exe-project) > cEvtWrapper ...(a private Class in your normal project) > cFactory ...(a private Class in your normal project) > > > Currently you are doing this (with only cAxExeThread): > '** presumably in a Form > Private WithEvents oAxExeThread As cAxExeThread > Private Sub Form_Load() > Set oAxExeThread = New cAxExeThread > End Sub > > > Now, if you want something like an "Object-instance- > Array", which is able to raise "aggregated events", you > can do that with the already mentioned "two extra-classes". > > In cEvtWrapper: > '** this is now the threadclass-host, able to receive its events > Option Explicit > > Private WithEvents oAxExeThread As cAxExeThread > Private Dispatcher as cFactory 'we hold a reference to the factory here > > Friend Sub Init(F as cFactory) 'the init-procedure, called from cFactory > Set Dispatcher = F 'just keep the Factory-reference in 'Dispatcher' > Set oAxExeThread = New cAxExeThread 'and create the Thread-instance > End Sub > > Private Sub oAxExeThread_SomeEvent() 'this is the normal Thread-EventProc > Dim EventName As String > EventName = "SomeEvent" > Dispatcher.DelegateEventFor oAxExeThread, EventName > End Sub > > Now in cFactory: > Option Explicit > > Event ThreadEventOn(oThread as cAxExeThread, EventName$) > > Public Col as New Collection 'we just store all the cEvtWrappers here > > Public Sub AddThread() 'this creates and adds a new Thread > Dim oEvtWrapper as cEvtWrapper > Set oEvtWrapper = New cEvtWrapper 'create a new wrapper... > oEvtWrapper.Init Me '...and indirectly a thread inside the wrapper > Col.Add oEvtWrapper 'finally we keep a reference in mCol > End Sub > > Friend Sub DelegateEventFor(oThread as cAxExeThread, EventName$) > RaiseEvent ThreadEventOn(oThread, EventName) > End Sub > > Public Sub CleanUp() > Set Col = Nothing > End Sub > > > Not that many lines of code till here, it's more the indirections > which can cause "some confusion" at the first sight. > Also, the above is just air-code - please adapt it appropriately > to your needs first. > > But with these two classes, you can now write in your Form: > > Private WithEvents oFactory as cFactory > > Private Sub Form_Load() > dim i& > Set oFactory = New cFactory > For i = 1 to N > oFactory.AddThread > Next i > End Sub > > Sub oFactory_ThreadEventOn(oThread as cAxExeThread, EventName$) > 'here you will receive the Events from all added threads, > 'oThread specifies the Thread-instance the Event in question > 'was raised from > End Sub > > Private Sub Form_UnLoad() > oFactory.CleanUp > End Sub > > Olaf > > > . > |