Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

similar Hand coded forms 2

Status
Not open for further replies.

beedubau

Programmer
Jan 7, 2003
97
AU
I have a number of similar forms - the only differences are the composition of a grid and a label caption.

Each form has 7 identical buttons coded as this example

Code:
ADD OBJECT cmdexit AS COMMANDBUTTON WITH ;
		TOP = 300 + 450, ;
		LEFT = 400 + 650, ;
		HEIGHT = 27, ;
		WIDTH = 84, ;
		FONTBOLD = .T. ,;
		FORECOLOR = RGB(255,0,0), ;
		CAPTION = label_cmdP02 ,;
		NAME = "cmdExit"

Is there any way I can create a set of buttons and use them on each of the forms?

Thanks

Bryan

 
Bryan,

You say it's a "hand-coded" form. I take that to mean that you are coding it in a PRG file, rather than using the form designer.

If that's right, the easiest way is to create a class for your buttons. Use the DEFINE CLASS construct. Base the class on a command group container. Write code to add the seven buttons and set their properties, just as you are doing now.

From now on, in your form-definition code, just add the new class, rather than the individual buttons. There'll be no need to set their individual properties again, unless you want to override any of them.

If I've got this wrong and you are using the form designer, proceed as follow.

Open one of your forms (one that already has the seven buttons on it) in the form designer. Multi-select the seven buttons. Go to File / Save As Class. Select "save selection". Specify a visual class library (it will be created if it doesn't already exist), and a name for the class. Finally, add the class to the project manager.

From now on, you can just add the class to a form by dragging it from the project manager.

With both of the above techniques, note that you will have an extra level of containership. So, instead of referring to, say, THISFORM.cmdExit, you will have to refer to THISFORM.MyClass.cmdExit, or something similar.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
THanks Mike,

I'll give it a go - this is a new step for me.


Regards

Bryan
 
Hi Mike,

Yes I am coding it in a PRG file.

I have defined a class containing the buttons as you suggest.

I am unclear of your instruction

<From now on, in your form-definition code, just add the new class,>

I have the class defined in one of the forms - is this correct?

At what point will the class be defined if another of the forms is run first?

How do I add the new class , and where in the prg. The form of the prg is

Preliminary work on the table
then DO Domygrid

Proc Domygrid has

Code:
ooForm1=NEWOBJECT("oForm1")

_SCREEN.VISIBLE = .T.
ooGsForm1.SHOW

Then a number of Defines including the one mentioned above.

1 Some DEFINE CLASS gs_abcd AS TEXTBOX types for clicking on grid cells.

2 DEFINE CLASS oForm1 AS FORM with an ADD OBJECT grid1 AS GRID

3 DEFINE CLASS imageColumn AS COLUMN

4 DEFINE CLASS rowImage AS IMAGE

5 DEFINE CLASS mycmdbuttons as Container

I am unable to get into the form in the debugger to see why it doesn't run. I have a SET STEP ON in Domygrid prior to the NEWOBJECT line and one in the forms INIT but I get an error when it gets to the NEWOBJECT command and I can't get past it.

Hoping you can help me get past this last step.

Regards

Bryan










 
Bryan,

I have the class defined in one of the forms - is this correct?

Not really. If you mean that you have the DEFINE CLASS inside the class definition of a form, that is not correct. You can't nest class definitions.

You can put the DEFINE CLASS for the buttons in its own file, provided that file is already open on the call stack. Alternatively, you can put it in the same file as your form definition, but then it must come after the form definition, and not inside it.

For an example, see Example 2 in the Help on DEFINE CLASS (ignore the fact that their class is an OLE control; that doesn't affect the basic principle).

In fact, there's quite a lot of information about this in Help. It might be worth perusing it for a while.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Thanks for that.

Sorry - when I said
'I have the class defined in one of the forms - is this correct?'
I meant

' in one of the 7 prg files'

I had looked at the Help but wasn't aware that it was generic - so I'll go back and have another look.

Regards

Bryan
 
Bryan - Mike's given what you need and held his tongue about why you're doing things this way. While hand-coded classes are very useful, especially when building "engine" kinds of things, for forms and other visual objects, it makes a lot more sense to use the Form Designer. Coding classes by hand is tedious work and doesn't buy you any advantages.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top