FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to change property form another form?
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
pit



Joined: 19 Aug 2008
Posts: 4

PostPosted: Tue Aug 19, 2008 8:33 am    Post subject: How to change property form another form? Reply with quote

I created a MainForm and a Form in sepatete files. Then I imported the Form module in the MainForm. I manged only to open Form from Mainform but after that I would like to change properties of objects in MainForm by events performed in Form. Now only thing I can recieve is Access Violation.
How can I do that?
Back to top
View user's profile Send private message Send e-mail
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Aug 21, 2008 3:46 pm    Post subject: Re: How to change property form another form? Reply with quote

Did you create a new instance of the form?
Code:
OtherForm other;
   ...
other = new OtherForm();
   ...
other.stuff(); // works now
Back to top
View user's profile Send private message
pit



Joined: 19 Aug 2008
Posts: 4

PostPosted: Fri Aug 22, 2008 9:14 am    Post subject: Reply with quote

Well, here's what I mean. All I want is to split a code into different files. I should have shown the code at the first post. The most important question for me is situated in the lines "//How to change ... from here ??".

File 1 - the main;
Code:
/*
   Generated by Entice Designer
   Entice Designer written by Christopher E. Miller
   www.dprogramming.com/entice.php
*/

import dfl.all;
import myform2.d;


class MyForm: dfl.form.Form
{
   // Do not modify or move this block of variables.
   //~Entice Designer variables begin here.
   dfl.label.Label label1;
   //~Entice Designer variables end here.
   
   
   this()
   {
      initializeMyForm();
      
      //@  Other MyForm initialization code here.
               startMyForm2();

      
   }
   
   
   private void initializeMyForm()
   {
      // Do not manually modify this function.
      //~Entice Designer 0.8.5.02 code begins here.
      //~DFL Form
      text = "My Form";
      clientSize = dfl.all.Size(284, 264);
      //~DFL dfl.label.Label=label1
      label1 = new dfl.label.Label();
      label1.name = "label1";
      label1.bounds = dfl.all.Rect(16, 40, 136, 40);
      label1.parent = this;
      //~Entice Designer 0.8.5.02 code ends here.

   }
        private void startMyForm2(){
        auto newForm = new MyForm2;
        newForm.show();
        newForm.button1.click ~= &changeLabel1inMyForm(){
        }
        private void changeLabel1inMyForm(Control sender, EventArgs ea){
        // How to change label1.text from here ??

        }
}


int main()
{
   int result = 0;
   
   try
   {
      Application.enableVisualStyles();
      
      //@  Other application initialization code here.
      
      Application.run(new MyForm());
   }
   catch(Object o)
   {
      msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
      
      result = 1;
   }
   
   return result;
}

File 2 - with the new "form" definition;
Code:

/*
   Generated by Entice Designer
   Entice Designer written by Christopher E. Miller
   www.dprogramming.com/entice.php
*/

import dfl.all;


class MyForm2: dfl.form.Form
{
   // Do not modify or move this block of variables.
   //~Entice Designer variables begin here.
   dfl.button.Button button1;
   //~Entice Designer variables end here.
   
   
   this()
   {
      initializeMyForm();
      
      //@  Other MyForm initialization code here.
      
   }
   
   
   private void initializeMyForm()
   {
      // Do not manually modify this function.
      //~Entice Designer 0.8.5.02 code begins here.
      //~DFL Form
      text = "My Form";
      clientSize = dfl.all.Size(284, 264);
      //~DFL dfl.button.Button=button1
      button1 = new dfl.button.Button();
      button1.name = "button1";
      button1.bounds = dfl.all.Rect(48, 48, 120, 40);
      button1.parent = this;
      //~Entice Designer 0.8.5.02 code ends here.
                button1.click ~= &changeLabel1inMyForm(){
                }
   }
        private void changeLabel1inMyForm(Control sender, EventArgs ea){
        // How to change Myform.label1.text from here ??

        }

}



I'm beginner and I haven't seen any DFL example with code divided into many files. But for me it would be much easier to see one.
Back to top
View user's profile Send private message Send e-mail
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Aug 29, 2008 10:43 am    Post subject: Reply with quote

Delegate literals and nested functions only work with event callbacks if you're sure the event won't be fired after the function it's in returns. You'll need to use a non-static member function.

Example:
Code:
class MyForm: Form
{
   this()
   {
      click ~= &form_click;   // Add click event handler.
   }
   
   private void form_click(Object sender, EventArgs ea)
   {
      // Handle event here.
   }
}
Back to top
View user's profile Send private message
pit



Joined: 19 Aug 2008
Posts: 4

PostPosted: Sun Aug 31, 2008 6:31 am    Post subject: Reply with quote

Thanks for your reply. I need to give more time to learn D.

BTW. Appreciate your work.
Back to top
View user's profile Send private message Send e-mail
Engineer



Joined: 15 Feb 2008
Posts: 1

PostPosted: Fri Sep 05, 2008 11:46 am    Post subject: Reply with quote

Hi,

I have the same problem (but only in one file). A MainForm with a listbox and other stuff and a SubForm with a textbox and a button to add items to the listbox of the MainForm. I don't get any error but I'm also not able to add an item, nothing happens after the SubForm is being closed.

Function in Class MainForm:
Code:

...
private void addlistitem(char[] ric, char[] funktion)
   {
       if (funktion != "")
        {
            MainForm.listBox1.items.add(ric~":"~funktion);
        } else
        {
            MainForm.listBox1.items.add(ric);
        }
   }

Call in Class SubForm:
Code:

...
auto MainForm = new MainForm();
                    MainForm.addlistitem(textBoxB3.text,textBoxB1.text);
                    SubForm.close();


And another Question, is it possible to disable the MainForm while the SubForm is open an enable it again after the users closes the SubForm? MainForm.enabled = false worked fine but MainForm.enabled = true has no effect in the SubForm. Looks like the same cause. Thanks in advance and btw awesome work Chris.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Tue Sep 09, 2008 9:46 am    Post subject: Reply with quote

Engineer, I'm not sure off hand, but I'm not sure why you're using 'auto'; I think that usage is outdated and might be destructing the form early. It would be helpful if you would provide a small, reproducable working example that I can run through the compiler and test.
-Chris
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Sep 11, 2008 11:15 am    Post subject: Reply with quote

Engineer wrote:
And another Question, is it possible to disable the MainForm while the SubForm is open an enable it again after the users closes the SubForm? MainForm.enabled = false worked fine but MainForm.enabled = true has no effect in the SubForm. Looks like the same cause. Thanks in advance and btw awesome work Chris.

Sounds like you want a "modal dialog" and you get it with Form.showDialog.
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Dec 05, 2009 6:54 pm    Post subject: Reply with quote

just to keep the idea in the same thread...

How do i access the various properties of an imported class? For example: I have this program,
Code:
import dfl.all;
import myform2;

void main()
{
  Form d = new MyForm();
  d.text = "Hello...";
  //d.Name.text = "name";
  d.show();
}


and this is the imported class,

Code:
/*
   Generated by Entice Designer
   Entice Designer written by Christopher E. Miller
   www.dprogramming.com/entice.php
*/

import dfl.all;


class MyForm: dfl.form.Form
{
  // Do not modify or move this block of variables.
  //~Entice Designer variables begin here.
  dfl.textbox.TextBox Name;
  //~Entice Designer variables end here.
 
 
  this()
  {
    initializeMyForm();
   
    //@  Other MyForm initialization code here.
   
  }
 
 
  private void initializeMyForm()
  {
    // Do not manually modify this function.
    //~Entice Designer 0.8.6pre4 code begins here.
    //~DFL Form
    text = "My Form";
    clientSize = dfl.all.Size(292, 273);
    //~DFL dfl.textbox.TextBox=Name
    Name = new dfl.textbox.TextBox();
    Name.name = "Name";
    Name.bounds = dfl.all.Rect(24, 8, 176, 24);
    Name.parent = this;
    //~Entice Designer 0.8.6pre4 code ends here.
  }
}



the above compiles without any problems, but if I change it to this,
Code:
import dfl.all;
import myform2;

void main()
{
  Form d = new MyForm();
  d.text = "Hello...";
  d.Name.text = "name";
  d.show();
}


I get this error,
Code:

19:46:19.65>build -I..;c:\D\dmd\import -version=gui -version=Phobos testDFL.d
testDFL.d(8): Error: no property 'Name' for type 'dfl.form.Form'
testDFL.d(8): Error: no property 'text' for type 'int'
testDFL.d(8): Error: constant 1.text is not an lvalue
testDFL.d(8): Error: cannot implicitly convert expression ("name") of type char[4u] to int


So, somehow, though, I can changed the Form's text, I can not change the class variables.

Any help would be greatly appreciated.

thanks,

jose
Back to top
View user's profile Send private message
AutoPython



Joined: 05 Dec 2009
Posts: 12

PostPosted: Sat Dec 05, 2009 9:02 pm    Post subject: Reply with quote

You could try returning Name.

Code:

  private void initializeMyForm()
  {
    // Do not manually modify this function.
    //~Entice Designer 0.8.6pre4 code begins here.
    //~DFL Form
    text = "My Form";
    clientSize = dfl.all.Size(292, 273);
    //~DFL dfl.textbox.TextBox=Name
    Name = new dfl.textbox.TextBox();
    Name.name = "Name";
    Name.bounds = dfl.all.Rect(24, 8, 176, 24);
    Name.parent = this;
    //~Entice Designer 0.8.6pre4 code ends here.
    return Name;
  }


I can't think of anything else atm, nor can I test it because something is going wrong with my DFL library.
[/code]
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Dec 05, 2009 9:29 pm    Post subject: Reply with quote

I don't think that is correct, since I am going to have a bunch of this variables. And that is what class is all about, to pass all of this variables under one variable.

I know I am missing something easy, but I can not come up with it.

thanks,

jose
Back to top
View user's profile Send private message
AutoPython



Joined: 05 Dec 2009
Posts: 12

PostPosted: Sat Dec 05, 2009 10:23 pm    Post subject: Reply with quote

There is some easy Rolling Eyes .
Inheritance.

Code:

class a ()
{
    chr[] some_var = "a";
}

class b:a()
{
    writef(some_var);
}



Or you can try

Code:

  public void initializeMyForm()
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Dec 05, 2009 10:40 pm    Post subject: Reply with quote

I tried the public void initializeMyForm() and that did not work. I do not want to try the other one because the final Class will have many more variables and the code is going to get very ugly with the repetitive code.

thanks.
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Dec 05, 2009 11:00 pm    Post subject: Reply with quote

Just to leave the result here, this works:
Code:
import dfl.all;
import myform2;

void main()
{
  auto d = new MyForm();
  d.text = "Hello...";
  d.Name.text = "name";
  d.show();
}[quote]

I got it from the D Learn NewsGroup.[/quote]
Back to top
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Sat Dec 05, 2009 11:01 pm    Post subject: Reply with quote

Just to leave the result here, this works:
Code:
import dfl.all;
import myform2;

void main()
{
  auto d = new MyForm();
  d.text = "Hello...";
  d.Name.text = "name";
  d.show();
}


I got it from the D Learn NewsGroup.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group