I'm trying to see if eC's RTTI magic can be used to store a subclass as part of the class_data.
This could be usefull for modular design, plugins, and so on...
This example should add a "My" tab in addition to the existing "Test" tab.
Code: Select all
import "ecere"
class Form1 : Window
{
text = "Form1";
background = activeBorder;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 640, 320 };
TabControl tabControl
{
this, background = activeBorder, anchor = { left = 8, top = 4, right = 8, bottom = 8 };
};
TestTab testTab { this, tabControl = tabControl };
bool OnCreate()
{
OldLink link;
for(link = class(Integration).derivatives.first; link; link = link.next)
{
subclass(Integration) integration = link.data;
subclass(IntegrationTab) tabClass = integration.tabClass;
IntegrationTab tab = eInstance_New(tabClass);
if(tab)
{
incref tab;
tab.master = this;
tab.tabControl = tabControl;
tab.Create();
}
}
return true;
}
}
class TestTab : Tab
{
text = "Test";
background = activeBorder;
tabCycle = true;
}
class IntegrationTab : Tab
{
text = "Class";
background = activeBorder;
tabCycle = true;
}
class Integration
{
class_data subclass(IntegrationTab) tabClass;
class_property subclass(IntegrationTab) tabClass
{
set { class_data(tabClass) = value; }
get { return class_data(tabClass); }
}
class_data char * tabClassName;
class_property char * tabClassName
{
set { class_data(tabClassName) = value; }
get { return class_data(tabClassName); }
}
}
class MyIntegrationTab : IntegrationTab
{
text = "My";
}
class MyIntegration : Integration
{
// It is important that MyIntegrationTab be defined before setting this class_property.
class_property(tabClass) = class(MyIntegrationTab);
class_property(tabClassName) = "MyIntegrationTab";
}
Form1 form1 {};
Cheers,
-redj