Solved

Procedure and AddObject

Posted on 2010-09-24
7
357 Views
Last Modified: 2012-05-10
So I created a Form, Tree, Container...

I'm using the below approach to Add an object (container) in right pane and then display something inside the container:

Define Form - For Form
Create a Top Level Form

   Add Object Tree as ......

   PROCEDURE Tree.NodeClick
   LPARAMETERS Node
         ss=Node.FullPath

         IF SS="Item2"
                AllObjectCont=CREATEOBJECT("CommonForm")
      AllObjectCont.AddObject("AllObjectCont","ContDef")
      AllObjectCont.Show
      READ EVENTS
         else
         endif
    endproc
ENDDEFINE - for Form

DEFINE CLASS CommonForm as Form

      Top=10
      Left=304
      Height=454
      Width=287
      visible=.t.
      borderstyle = 2
      AlwaysOnTop=.t.
      DoCreate = .T.
      controbox=.f.
      MinButton=.f.
      MaxButton=.t.
      autocenter = .f.
      autosize =.t.
      LockScreen=.f.
      Movable=.t.
      ngridx = 0
      ngridy = 0
      Name = "CommonForm"
      ShowWindow = 1
      TitleBar=0
      Anchor=15
      Visible=.t.

ENDDEFINE


When I click on Item2 the form "CommonForm" is not displayed - it doesn't give any error also.

Am I doing something wrong here?

I want to define a Container in Right Pane when someone clicks on the Tree Nodes and then should be able to place items in the Containers.

Thanks!
SP

 
0
Comment
Question by:Nirmal Sharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 35

Author Comment

by:Nirmal Sharma
ID: 33755136
thisform.AddObject("Conts","Container")
thisform.Conts.Visible=.t.

it works!

once question I have is - how do I check if the same container is already defined and close it before adding again?

Thanks!
SP
                  
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
ID: 33755240
When adding object with Addobjects you need to set them visible.

Four other things:
1. You shouldn't name the container you put on the form the same as the object which holds the form reference. It's not against any rule, but a source for confusion.

2. Why create a container with all things inside and put it on a form rather than creating a form itself as class, then you'd create the form you want and show it, done.

3. The Anchor property of the form also is useless. Either a form is resizable or not, but it's not anchored to any other container, even not the _screen. It's objects on the form which need anchoring, not the form.

4. READ EVENTS is not meant for doing with every form you create, you should only have on read events in a min.prg after intialising your application, started a menu and maybe started a main form. If you want execution to stop while a form runs, make the form modal, but better yet try to cope without any modal form, as long as there is one modal form the user can't switch elsewhere in your application. The read events is rather the resting place outside any form caller method or menu that the runtime resides on as long as there is no user input, most of the time, but there should only be one of that.

IF SS="Item2"
    oForm = CREATEOBJECT("CommonForm")
    oForm.AddObject("AllObjectCont","ContDef")
    oForm.AllObjectCont.visible = .T. && this was missing
    oForm.Show(1)
Else
Endif

And if you don't Show(1), but Sho() or Show(2) code continues to run, you can use another item of the treeview to start another form parallel to "Commonform" with the "ContDef" container on it.

Bye, Olaf.
0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 500 total points
ID: 33755258
If you do that code again, you again start with an empty commonform, so there is no need to check if the container is already defined. You can create as many objects of some class as you want.

As you run the form modal (via Read events or with my alternative Show(1)) there is no chance you get there again before the form is closed.

Bye, Olaf.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Author Comment

by:Nirmal Sharma
ID: 33755682
Thanks Olaf!

Now I have a new problem - anchoring does not work with the new Container/Form added using the AddObject method when Top Level form is already maximized.

SP
0
 
LVL 35

Author Comment

by:Nirmal Sharma
ID: 33755937
>>>As you run the form modal (via Read events or with my alternative Show(1)) there is no chance you get there again before the form is closed.

This is not I want! Show(1) method doesn't allow me to select anything in the Left Pane (tree).

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 33757696
Anything you put on a form has it's original position then and anchoring works from that moment on, but you can't put a small container on a large form and expect it to resize in relation to the forms base size, no.

Composing forms at runtime is not the way to go anyway.


In regard to Show(1) vs READ EVENTS:

Okay, but you also can't want to stay in the nodeclick event until a CLEAR EVENTS is issued. The problem without SHOW(1) or READ EVENTS is, that the form variable is released when the form finishes and so the form does not persist. You need to add that form reference somewhere it persist, eg let a form handler object handle form creation. This could be done from the treeview menu, when you simply do this in the treeview init:
This.Addobject("forms","collection")

And in the nodeclick after creating and showing the form simply do
This.forms.add(oForm)

This keeps the form alive, and the form reference is removed from the collection, when the form is closed.

With your read events solution, where do you put a clear events? Nowhere? You will not be able to close foxpro then, when you're in a read events. The nodeclick method never finishes.

Bye, Olaf.
0
 
LVL 35

Author Closing Comment

by:Nirmal Sharma
ID: 34309577
Thanks!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question