I have a situation where objects created later need to be "rendered" (cast?, reclassifed?) as one of many specialised versions of those objects. In the following code all went fine until I added the check to ensure that the specialised class is a descendant of the original class.
Now it fails when compiling at the marked line with an "Unexpected Object" object error. Can anyone tell me what I'm doing wrong here? -----code---- Public Sub Main() Dim obj1 As New Parent Dim obj2 As Child1 Dim c1 As New Collection With obj1 .Name = "c1" .Type = "1" End With c1.Add(obj1, obj1.Name) obj1 = Morph(obj1, "child1") c1[obj1.Name] = obj1 Print obj1 Is Parent Print obj1 Is Child1 Print obj1 Is Child2 '(a different subtype of "parent") Print Object.Class(obj1).Count End Private Function Morph(source As Object, targetname As String) As Object Dim nt As Object Dim propname As String nt = Object.New(targetname) If Not(nt Is Object.Class(source)) Then ' <<--- HERE! Error.Raise("Illegal morph") Else For Each sprop In Object.Class(source) If Object.Class(source)[sProp].Kind = Class.Property Then Object.SetProperty(nt, sProp, Object.GetProperty(source, sProp)) Endif Next Endif Return nt End --- end ---- tia Bruce ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user