Ecere SDK/eC Forums • View topic - eC Magic, RTTI, modular design, plugins... oh!, and tabs.




Ecere SDK/eC Forums

Ecere Developers Community

eC Magic, RTTI, modular design, plugins... oh!, and tabs.

General help with the eC language.

eC Magic, RTTI, modular design, plugins... oh!, and tabs.

Postby redj » Fri Apr 09, 2010 10:50 pm

Greetings Ecere people. ;-)

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 {};


Try it, learn from it, let me know if you can help.

Cheers,

-redj
redj
 
Posts: 107
Joined: Sun Jan 17, 2010 10:03 am

Re: eC Magic, RTTI, modular design, plugins... oh!, and tabs.

Postby redj » Wed Apr 28, 2010 10:28 pm

It's working :D -- I've updated the first post with the correct code.
redj
 
Posts: 107
Joined: Sun Jan 17, 2010 10:03 am

Re: eC Magic, RTTI, modular design, plugins... oh!, and tabs.

Postby redj » Wed Apr 28, 2010 11:04 pm

More coming soon.
redj
 
Posts: 107
Joined: Sun Jan 17, 2010 10:03 am


Return to eC Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron