Hi, I wasn't able to cover the problem in one subject line...hence the
slightly mysterious description.
Ok, this is the problem. I have a method called GetField, at the
moment this method returns a iField interface. This is a generic
object that contains the majority of properties and methods related
to window controls. The method GetField is part of a class called
cForm with an interface iForm.
Now, I have a new control or iField as I called it. A Tab control.
Of course the tab control is far more different than say a label or
an Edit box control so my idea is to create a new class cTabControl
with an interface iTabControl.
Ok, so far so good. everybody following this ?
Now, I also have
another class called cForm which has a method called AddField(). The
AddField method takes a parameter (ByVal ClsField as iField) this works
for Labels, Checkboxes, Editboxes but won't work for the iTabControl
interface.
So my first question. How can I pass object reference to a method where
the object can be different interfaces ?
also, How can I obtain an object reference using the method GetField(n)
, where n is the field index number, for which the reference can be
either iField or iTabControl. I'm not working with COM objects, just
PB classes.
So, in short... the iField interface is now passed as a parameter to
AddField(ByVal ClsField as iField) but I would like to pass any kind of
object to this method (iTabControl f.i. as well).
Ok, maybe it's because I'm writing this that my brain starts working. I was thinking of using a UDT with two members (pObjPtr holding the ObjPtr of the object I would like to pass and bType holding the type of the object.) Than
in stead of storing the iField in an array, I could store the UDT in an array and use a reverse method based on checking the type of object I've passed to retrieve the object using GetField. But then I use pointers instead of the
interface directly. Did I now just answer my own question or are there better approaches to this ? Like in Java one can return an object called Object which is the mother of all objects and then with InstanceOf determine the
object 'class' being returned. but that is Java and this is PB...
Thanks for reading !!
Cheers
Steven
slightly mysterious description.
Ok, this is the problem. I have a method called GetField, at the
moment this method returns a iField interface. This is a generic
object that contains the majority of properties and methods related
to window controls. The method GetField is part of a class called
cForm with an interface iForm.
Now, I have a new control or iField as I called it. A Tab control.
Of course the tab control is far more different than say a label or
an Edit box control so my idea is to create a new class cTabControl
with an interface iTabControl.
Ok, so far so good. everybody following this ?

another class called cForm which has a method called AddField(). The
AddField method takes a parameter (ByVal ClsField as iField) this works
for Labels, Checkboxes, Editboxes but won't work for the iTabControl
interface.
So my first question. How can I pass object reference to a method where
the object can be different interfaces ?
also, How can I obtain an object reference using the method GetField(n)
, where n is the field index number, for which the reference can be
either iField or iTabControl. I'm not working with COM objects, just
PB classes.
So, in short... the iField interface is now passed as a parameter to
AddField(ByVal ClsField as iField) but I would like to pass any kind of
object to this method (iTabControl f.i. as well).
Ok, maybe it's because I'm writing this that my brain starts working. I was thinking of using a UDT with two members (pObjPtr holding the ObjPtr of the object I would like to pass and bType holding the type of the object.) Than
in stead of storing the iField in an array, I could store the UDT in an array and use a reverse method based on checking the type of object I've passed to retrieve the object using GetField. But then I use pointers instead of the
interface directly. Did I now just answer my own question or are there better approaches to this ? Like in Java one can return an object called Object which is the mother of all objects and then with InstanceOf determine the
object 'class' being returned. but that is Java and this is PB...
Thanks for reading !!
Cheers
Steven
Comment