Ecere SDK/eC Forums
http://ecere.org/community/
Print view

Code Snippet04-Share data between forms(Wizard style)
http://ecere.org/community/viewtopic.php?f=5&t=170
Page 1 of 1
Author:  samsam598 [ Fri Aug 26, 2011 2:09 am ]
Post subject:  Code Snippet04-Share data between forms(Wizard style)

Purpose:Sharing variable between two forms.Pass a value to a variable (property version of Form 1 here)belongs to form1 and change its value in Form2.The caption of form1 and the text of label in form2 will indicate this change.A very simple wizard based application.
form1.ec

Code: Select all

 
import "ecere"
import "form2"
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = fixed;
   hasMinimize = true;
   hasClose = true;
   size = { 488, 192 };
   anchor = { horz = -31, vert = -133 };
   nativeDecorations = true;
 
   Button button1 
   {
      this, text = "(N)ext", altN, position = { 416, 128 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Form2 form2{};
         form2.Create();
 
 
         visible=false;
         return true;
      }
   };
   Picture picture1 { this, text = "picture1", anchor = { left = 16, top = 16, right = 16, bottom = 52 }, image = { "C:\\person\\ecere\\ecere\\ide\\res\\ecereBack.jpg" } };
 
   float version;
   public:
   property float version
   {
      set{version=value;}
      get{return version;}
   }
 
   char versionStr[32];
   property char* versionStr
  {
     get
     {
        char result[32];
        sprintf(result,"%.1f",version);
        strcpy(versionStr,result);
        return versionStr;
     }
  }
 
   void OnRedraw(Surface surface)
   {
     char caption[40];
     sprintf(caption,"MultiformApp-V%.1f",this.version);
     this.text=caption; 
 
   }
}
 
Form1 form1 {  version=1.0f;  };
 
form2.ec

Code: Select all

 
 
import "ecere"
import "form1"
 
class Form2 : Window
{
   text = "Form2";
   background = activeBorder;
   borderStyle = fixed;
   hasMinimize = true;
   hasClose = true;
   size = { 520, 152 };
   anchor = { horz = -28, vert = -140 };
   nativeDecorations = true;
 
   Button btnBack 
   {
      this, text = "(B)ack", altB, position = { 424, 72 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
 
         form1.visible=true; 
 
         Destroy(0);  
         return true;
      }
   };
   master=form1;
 
   bool OnClose(bool parentClosing)
   {
 
 
      form1.visible=true;  
 
      Destroy(0); 
      return true;
   }
   Label label1 { this, text = "label1", foreground = seaGreen, font = { "Tahoma", 16, bold = true, italic = true }, size = { 476, 45 }, position = { 16, 16 } };
 
   bool OnPostCreate(void)
   {
 
      char str[40];
      form1.version=form1.version+0.1f;
      sprintf(str,"The latest version of form1 is %.1f",form1.version);
 
      this.label1.text=str;
      return true;
   }
}
 
All times are UTC-05:00 Page 1 of 1