
classtree.prg
Code: Select all | Expand
#include "FiveWin.ch"static aClasses := {}function Main() local oWnd DEFINE WINDOW oWnd TITLE "Classes hierarchy" ACTIVATE WINDOW oWnd ; ON INIT BuildClassesTree( oWnd )return nilfunction BuildClassesTree( oWnd ) local n := 1, oClass, oTree, oItem, oChild while ! Empty( __ClassName( n ) ) AAdd( aClasses, TClass():New( __ClassName( n++ ) ) ) end for each oClass in aClasses oClass:GetSuper() next for each oClass in aClasses oClass:GetChilds() next oTree = TTreeView():New( 1, 1, oWnd ) oTree:nWidth = 152 // oTree:SetImageList( oImageList ) // oTree:Add( "Files" ) for each oClass in aClasses if Empty( oClass:cSuper ) oItem = oTree:Add( oClass:cName ) for each oChild in oClass:aChilds oItem:Add( oChild:cName ) next endif next oTree:Expand()return nilCLASS TClass DATA cName DATA cSuper DATA aChilds INIT {} METHOD New( cName ) METHOD GetSuper() METHOD GetChilds()ENDCLASSMETHOD New( cName ) CLASS TClass ::cName = cName ::cSuper = ""return SelfMETHOD GetSuper() CLASS TClass local oClass, oInstance := &( ::cName + "()" ) for each oClass in aClasses try if oInstance:IsDerivedFrom( oClass:cName ) .and. ::cName != oClass:cName ::cSuper = oClass:cName endif end nextreturn nilMETHOD GetChilds() CLASS TClass local oClass for each oClass in aClasses if oClass:cSuper == ::cName AAdd( ::aChilds, oClass ) endif nextreturn nil function Error()return ErrorNew()
