Grigore, Thanks for the nice warm welcome to the big leagues! Over the years I have survived of a single application and - for the most part - have always been able to use the GUI for development.
My problem started with changing the record source of a grid with an embedded checkbox. I just thought it would be easier to deal with the concept by using a command button.... Bottom line - my problem was created by me and I now see how it can be handled properly with simple code. Thanks again. Someday I just might have to dig into your comments! Carl Lindner -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Grigore Dolghin Sent: Sunday, March 28, 2010 2:19 PM To: [email protected] Subject: Re: VFP9-SP2 addobject - Method Code You can't do that. Adding method code in runtime is not supported (it never was). You have several workarounds, though. #1. Create your own button class, enter the code in the Click event of the button class then add the button in runtime with AddObject. (You could set the properties in design mode so you won't be needed to write the .width=50 code and such). #2. Visual FoxPro allows you to execute code using ExecScript or/and by saving it in a prg file, compile it and run it, all in runtime. The only problem is how to make the button's click to run your code, and here comes BindEvent. Your code should look similar to this (I am writing it directly in mail client so there may be bugs, but you'll get the general idea): *-- First - you'll need a way to run a piece of code by receiving the actual code location. I would suggest to add a method in the form: MyMethod: local lcCode lcCode = filetostr(ThisForm.CodeFile) && now you have the code in memory ExecScript(tcCode) With ThisForm .AddObject("oCommand", "commandbutton") EndWith ThisForm.CodeFile = "C:\MyProgram\CodeToBeRunInRuntime.prg" *-- Or, alternatively, you can generate the prg on the fly as needed and save it to that file name, then assign the filename to the CodeFile property. BindEvent("ThisForm.oCommand", "Click", ThisForm, MyMethod) && MyMethod will try to read the content of the ThisForm.CodeFile property. *----------------------- Experiment and be creative. ;) Hope this helps. On Sun, Mar 28, 2010 at 9:04 PM, Carl Lindner <[email protected]> wrote: > Thanks, but I cannot make it work > > I am not sure I understand. The procedure/endproc.... > > I cannot place before thisform.addobject, directly after > thisform.addobject, > between the with/endwith, or after the endwith. My code is in the init of > the form.... > > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On Behalf > Of Aida I. Rivera-Benítez, MSMIS > Sent: Sunday, March 28, 2010 1:45 PM > To: ProFox Email List > Subject: Re: VFP9-SP2 addobject - Method Code > > PROCEDURE Click > ***Your code goes here > ENDPROCEDURE > > The same for Valid. > > AiR > Aida I. Rivera-Benítez, MSMIS > AiR Information Systems, Inc. > San Juan, Puerto Rico > > ----------------------------------------------- > From: "Carl Lindner" <[email protected]> > Sent: Sunday, March 28, 2010 1:31 PM > To: <[email protected]> > Subject: VFP9-SP2 addobject - Method Code > > > Hey guys, I can use some help. > > > > thisform.addobject("ocommand","commandbutton") > > with thisform.ocommand > > .top=60 > > .height= 50 > > .width= 50 > > .visible=.t. > > .left=1 > > endwith > > > > I run the above in the init code of a form. It creates a clickable > > command > > button. How would I add code for a valid, or click? > > > > Thanks. > > > > Carl Lindner > > > > [email protected] > > > > [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/000001cacea6$a237f670$e6a7e3...@com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

