On Sat, 07 Nov 2015, zainudin ahmad wrote: > On Fri, Nov 6, 2015 at 12:04 PM, Tobias Boege <tabo...@gmail.com> wrote: > > > Hi, > > > > in my project I have the need to enumerate all classes from my current > > project (not from components) for which > > > > hClass Is X > > > > is true for some fixed class X, once at startup. I think I tried > > > > For Each hClass In Classes > > hCurrent = hClass > > While hCurrent.Parent > > If hCurrent.Parent = Classes["X"] Then > > aRes.Add(hClass) > > Break > > Endif > > hCurrent = hCurrent.Parent > > Wend > > Next > > > > (written from memory, but it gets the idea across). However, this does not > > work as Classes can only access the already loaded classes. > > > > Is there a way to enumerate _all_ classes in the current project or to > > force > > loading of all remaining classes from the project? I have no particular > > technical problem with hard-coding the desired list instead of computing it > > but I want to know if I *could* compute it. > > > May be this code can help. > > Public Sub Main() > > Dim sClass As String > > Print "Count : " & Dir(".gambas").Count & "\n" > > For Each sClass In Dir(".gambas") > Print sClass; > Try Print "-->" & Object.Class(Object.New(sClass)).Parent.Name '<-- > this make class load into memory > If Error Then Print > Next > > End >
As with most hacks, it's a nice idea :-) (also works in executable archives). But since some classes may be Create Private, using Object.New() to force them to load is not a good idea. I have adapted the code to use Class.Load(). Thank you, although I'm not sure if I'll continue this way. Regards, Tobi -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk ------------------------------------------------------------------------------ _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user