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!

How to change one method in several object at the same time?

Status
Not open for further replies.

Hannes214

IS-IT--Management
Jan 30, 2006
45
DE
Hi

I have a form with several objects and they all will have the same click-method...

Is there a possibility to change that method of all these object at the same time???

I hope for a reply.

Hannes214

IT-Management
( FoxPro-Newbi :eek:) )
 
Next time do following:
In all Click Events of these objects put:

thisForm.CustomClickEvent()

Make a new method in the form named CustomClickEvent and program all you need there. Next time when you need to change the code just change it in that method.

Good programing style is "Every Event calls Method" That means, when you have to put some code in Object Event make method and call that method from the event.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Hannes,

Are all the objects of the same type? For example, are they all command buttons?

If so, you could try this ....

Write the code in the Click event of one of the buttons. Also, set any properties of that button that are common to all the buttons.

In the form designer, select the button, and then select File / Save As Class. Invent a name for the button class that you are about to create, and specify a VCX library to store it in. If you don't already have a VCX, enter a path and file name and it will be created for you.

You now have a class that contains the code and properties that you want all the buttons to share.

The next step is to delete all the existing buttons from the form(s). Add the VCX to the Classes tab on the project manager. Drill down into the VCX, and drag the new class onto the form. Repeat the drag for each button that you want to appear on the form.

I know this sounds like a lot of trouble, and it might not be worth the effort in your case. If you don't have time to try it, I suggest you resort to cut and paste this time, but invest some time in designing a proper class library for the future.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Thanks for all the reply...

Now..

Yes, all the objects are from the same type.. Label
I programm an overview about the month of a year and planning the vacations.. for our company

So I show 31 days (a month) for 20 employee on a form... 620 Labels.. That's all no problems...
I first programmed one Label and duplicate it to that number.. but thats a stupid way... so I wrote a method like bborissov told.. ok

But now I have to change the click-method from all these Labels so they call that one method of the form...

Delete all Labels and duplicate one is no solution, because all have a special name...

So.. how can I change the Click-Methode of all these Labels without a lot of work...

IT-Management
( FoxPro-Newbi :eek:) )
 
Make a very good backup.
Then open your form as table
Code:
USE MyForm.SCX EXCLUSIVE
Filter the records by Class, something like:
Code:
SET FILTER TO ALLTRIM(Class) == [Label]
BROWSE NORMAL
Make sure that all records showed in browse window are only these records you want to change.
Then
Do this:
Code:
TEXT TO lcReplace NOSHOW
     PROCEDURE Click
           thisform.MyClickMethod()
     ENDPROC
ENDTEXT
REPLACE ALL Method WITH lcReplace
PACK
PACK MEMO
REINDEX
close your form
and:
Code:
COMPILE FORM MyForm

But as I said MAKE SURE YOU HAVE A GOOD BACKUP.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Hannes,

So, what you are saying is that you can't use a class-based solution. You are stuck with having to add the same line of code to many different objects.

Borislav's solution is a good possibility. Another would be to record a keystroke macro to do the job. If you haven't used keystroke macros, see the article "Use keyboard macros to speed up repetitive actions" at
The macro would use Alt-V C to open the code editing window. It would then type the code you want, then use Ctrl-W to close the window, and finally Tab to get to the next control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
O! And the BEST Solution, that combines both suggestions (mine and Mike's)
Create a Class for that label. Put all the code you need in it. Open your form as table, filter records so only records for that labeles to be showed. Then
Code:
REPLACE Class    WITH [YourClassName],;
        ClassLoc WITH [relative path to your classlib]\YourClassLib
        Methods WITH [],;
        ObjCode WITH []
PACK
PACK MEMO
REINDEX
USE
COMPILE FORM MyForm

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks for all that reply.... I will try them at monday :)

IT-Management
( FoxPro-Newbi :eek:) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top