Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Define class programmatically
Message
From
13/11/2003 04:57:40
 
 
To
12/11/2003 14:58:28
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00848966
Message ID:
00849434
Views:
22
Paul,

>Thanks for your reply - what I am not sure about is how you get the combo box to actually appear. What part of your program does this? Do you have to have it as a form? I have a define class program, and when I run it nothing happens. When I run yours, the combo box and form appear. I have received some great responses to this question, but am a little embarrassed to indicate that I cannot follow the others suggestions since it is not "step-by-step" and I am not knowledgeable about what they are suggesting. Every suggestion leads me to a Foxpro book where I look up what they are suggesting but I am unable to get to "the next level" and solve my problem. Since
I am not a great programmer, I usually need more help than the next guy. Any layman's help you can give would be greatly appreciated.


Let's aproach the problem by parts.

The first thing that sample code does is to create an object (variable oComboForm) that will be a reference to the form you are creating (frmComboTest):
 oComboForm = CreateObject ("frmComboTest")
 oComboForm.Show ()
The first statement (oComboForm = CreateObject ("frmComboTest")) is the one that performs the creation of the form, and the second one (oComboForm.Show ()) executes a default form's method (Show()) and makes it to appear, which means that the form is activated and visible and all its controls will be activated as well (that's how the combobox appears).

That form definition is made by means of a define class, where you set all properties needed to make it the way you want to:
 Define Class frmComboTest as Form
*------ ----- ------------ -- ----

        Height     =  80
        Width      = 210
        Name       = "frmComboTest"
        Caption    = " Form containing a ComboBox"

        WindowType =   1 
        Closable   =  .T.
        ControlBox =  .T.
        MaxButton  =  .F.
        MinButton  =  .F.
        Movable    =  .T.
        ZoomBox    =  .F.
        SizeBox    =  .F.
        AutoCenter =  .T.
        ShowWindow =   0 
Inside the class definition of that form you add all controls (Add Object) that will be part of it. In our case a combobox (cboMonths) and a commandbutton (cmdCancel). The same way you set the properties for the form (see above), you'll set the properties for the controls you are inserting:

This is for the combobox:
        Add Object cboMonths    as cPtrComboBox  with Top               =  25      , ;
                                                      Left              =  10      , ;
                                                      Width             =  80      , ;
                                                      RowSourceType     =   1      , ;
                                                      RowSource         = cMonths  , ;
                                                      ColumnCount      	=   1      , ;
                                                      ColumnWidths     	= "80"     , ;
                                                      Style            	=   2      , ;
                                                      DisplayCount     	=  12      , ;
                                                      Value             =   1
and this for the commandbutton:
        Add Object cmdCancel    as CommandButton with Top               =  20      , ;
                                                      Left              = 130      , ;
                                                      Height            =  25      , ;
                                                      Width             =  75      , ;
                                                      FontName          =  "Arial" , ;
                                                      FontSize          =   8      , ;
                                                      Cancel            = .T.      , ;
                                                      Caption           = "\<Close"
All that we've done until now defines the form we want to show and its controls. The next part is to define what will happen when events related to the form and its controls get fired. In this point you define those procedures that will treat those events.

The first one (Procedure cmdCancel.Click) will be fired when you click with the mouse in the cancel commandbutton (cmdCancel):
        Procedure cmdCancel.Click
*                 --------- -----
                  ThisForm.Release
        EndProc
It will release the form and will return control to the line following the oComboForm.Show () statement, will perform a Clear Events and end the program. If you wish, add the MessageBox() line to see what happens.
 oComboForm = CreateObject ("frmComboTest")
 oComboForm.Show ()

 MessageBox ("Form was released and execution control returned to 'here'")

 Clear Events
The second one (Procedure cboMonths.Click) will be fired when you click with the mouse in the cboMonths combobox:
        Procedure cboMonths.Click
*                 --------- -----
                  MessageBox ("You selected " + This.List (This.ListIndex) )
        EndProc
When this happens that method will be executed and will show what option in the combobox you selected.

The last one will be executed if you select the "X" control button in the forms title bar to exit it (instead of pressing the cancel commandbutton). Just try modifying that method (as below) ant make a test:
        Procedure QueryUnload
*                 -----------
                  MessageBox ("You pressed the "X" to exit!")
                  ThisForm.cmdCancel.Click
                  NoDefault
                  Return .T.
        EndProc
I'm not sure if this explanation is what you was thinking about, but experiment for a while with that code and try to follow to understand each step described.

Pardom me if it seems somewhat confusing, but I wish my english was better in order to make it more clear.

Regards,

Fernando
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform