The question I have is when the line "Delete @This" is executed, will all the memory of Car get returned to the memory allocator or just the amount of memory associated with Obj? Including the memory allocated to the String Make?

Second question.It does not look like the statement

This.xxx

would work as the second line of ReduceRefCount? Is there any simple generic way to make it work when there are hundreds of types derived from OBJ.

Third question.

Is there some way I can declare a variable "ObjType" in type OBJ that contains a FreeBasic type. So that I can store the type Car into it during the execution of the constructor for Car.

Then in a routine declared in ObjI can cast the Obj pointer @This to a Car pointer something like this

Just 2 preliminary remarks (let's start at the beginning):- To access a member field from an object pointer, you must use the "->" operator.(the "." operator is used for accessing a member field from an object reference)- To create a dynamic object, you defined an object pointer ("Ford"), but you must also allocate memory and construct data of the specified type by calling the "New" operator.(When it becomes useless, this dynamic object will have to be suppressed by calling the "Delete" operator)

wallyg wrote:The question I have is when the line "Delete @This" is executed, will all the memory of Car get returned to the memory allocator or just the amount of memory associated with Obj? Including the memory allocated to the String Make?

"Delete @This" induces 2 actions:- first, all data associated to the Type of "@This" ("Obj Ptr" in your case) will be destroyed.- then the allocated memory at address corresponding to the value of "@This" will be freed (whatever the type of "@This").So in your example, the "Make" member field will be not destroyed but all memory allocated for "Obj+Car" member fields will be freed, inducing a memory leak: the "1962 Mustang" character data in your example (it starts badly).

For the rest of your questions, all you want to do seems to me obscure, twisted and unsafe, so that I do not know what to say.

Is there some way I can declare a variable "ObjType" in type OBJ that contains a FreeBasic type. So that I can store the type Car into it during the execution of the constructor for Car.

Then in a routine declared in ObjI can cast the Obj pointer @This to a Car pointer

If you want to access a derived member field from a base pointer/reference, the better method is polymorphism (by virtual member procedures). If you want access derived field data, the better is so to add associated virtual properties allowing to access these data.All the rest is a terrible knitting unsafe.

Otherwise, the least awful would be to define "Obj Extends Object" in the type declaration, and so to be able to execute in any Obj procedure the kind of following code:

Is there some way I can declare a variable "ObjType" in type OBJ that contains a FreeBasic type. So that I can store the type Car into it during the execution of the constructor for Car.

Then in a routine declared in ObjI can cast the Obj pointer @This to a Car pointer

If you want to access a derived member field from a base pointer/reference, the better method is polymorphism (by virtual member procedures). If you want access derived field data, the better is so to add associated virtual properties allowing to access these data.All the rest is a terrible knitting unsafe.

Otherwise, the least awful would be to define "Obj Extends Object" in the type declaration, and so to be able to execute in any Obj procedure the kind of following code:

Yes this is what I want done, the problem is that there are currently 317 different types that @this can point to (many more to come over time). I wanted some generic way to do the cast without having a 317 branch If or Select statement in lots and lots of similar situations (then have to update each and every one a couple times a week as more types are added).

I have not done anything like that before, so I will go back to the FB manual and try to work out how that works. Is there any other documents that go into more detail than the current standard FB manual?

I have not done anything like that before, so I will go back to the FB manual and try to work out how that works. Is there any other documents that go into more detail than the current standard FB manual?

I'll say that the Manual is the best place to look for this info. That, and this forum of course =DThis is a simple approach to your problem (if I understood your requirement correctly):

/' The records in the table are all read-only, but you can easily implement a property setter to update its values if you like. However, sometimes it's easier to just remove the object from the table, create a new one, and add it to the table again. This is especially true if you keep the array sorted by, say, brand or year.'/sleep()

This code implements a very simple table of cars. Only barebones functionality is implemented (namely, adding a record to the table and presenting a report). However, the table is polymorphic, and will add any record that conforms to the ICarRecord interface. I provided a simple, generic Car class that has some read-only properties, and a polymorphic drive() procedure that 'drives' each car present in the table. Is this what you're trying to do? Or are there specific methods to call for each model of car?