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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RUN UDF at Design Time ?

Status
Not open for further replies.

NasibKalsi

Programmer
Jan 8, 2004
417
CA
Dear All:

Is there a way to execute a user defined Method of a user defined class at DESIGN TIME (not at run time), when the class(control) is dragged to the Form ?
 
Try this ....

First, use ASELOBJ() to get an object reference to the control. Then use GETPEM() to extract the code from the method you are interested in. You can then run the code via EXECSCRIPT().

I'd guess you'd have to write a little program that does all of that. I can't think of any way of automatically running the program at the point at which you drop the control on the form. But you could perhaps register the program as a builder, and run it by right-clicking on the control and choosing Builder.

What are you trying to achieve? There might be easy ways of getting to the same goal?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thank you Mike.
My lazy thinking is to have controls such as TextBox, EditBox, etc. surrounded by some 3D effets. That I will make a class where I will drag a TextBox and draw few Shape objects(Rectangles with colors, intensity). Then at design time (not at Run Time) I will drag this class object to a form and resize at will, where TextBox and Rectangles resize accordingly. I know that there is no immediate solution. There could be some other method(s) called designinit(), designload(), designresize() or something.

My Best
 
NasibKalsi,

I think you're going about this is slightly the wrong way. By all means, write some code to the resizing and other design time stuff. That makes good sense.

But don't make that code a method of the control you are dropping on the form. Instead, write a normal PRG, which you can run from the command window while the form is open in the designer. Or, going further, register the PRG as a builder, and run it by right-clicking on the control.

Either way, use ASELOBJ() to get the object reference to the classes in question.

Rick Schummer has written an excellent series of article on builders in FoxPro Advisor that tells you how to do this sort of thing. If you have FPA, you can also see my own article, "Beautify Your Forms", in the September 2003 issue; this gives similar ideas for adjusting properties in your forms at design time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

I fear that is the way to go. In fact having a builder is not bad, but as a developer I also have the choice on native controls to use a builder or not.

I wonder if it isn't the native resize event, which is used to adjust controls at design time, for example. Nevertheless, you might want to have code in it, that depends on a framework of other classes only available at runtime, so the seperate prg is indeed a godd idea.

I wonder if you can't hook calls to such prgs in other things, eg the class browser. At least, as that is available in source code, you could modify it. But it's scope is over, when a class is dragged to a form(class), or is it?

A project hook does not handle each new object, only new classes or other project files/components, so that won't work. But you might use a projekt hook to start some eventhandler each time a new form/formclass is created or modified. You might be able to do something with timers. Monitor what ASELOBJ() gives you at hand and see if it's one of your classes.

At least there is no such secret or magic prefix to eventnames as "design"resize, which might be used to trigger some code at design time. It's not the easiest thing to do such things at design time.

In some case I put some code into controls, that adopts the control layout at init() to the size of the outer container. That doesn't look good at design time, but works without building a builder. And you don't depend on a builder to resize your controls without the side effect, that the inner structure does not follow the outer size.

There is one other easy way: define some property "code" or whatever you like, then set it's value to [=somefunction()] in the designer, that function then is called even at design time, each time the designer opens that class. You just need to have a SET PROCEDURE setting.

That still does not handle resizing at the resize time, but it may be convenient enough. You might include somefunction() that does nothing at runtime in your exe, while you use somefunction() at designtime, that does something to the controls properties. You might try out =somefunction(THIS) to have an object reference, or you might need to make use of ASELOBJ(), haven't tried that yet, just an idea.

Bye, Olaf.
 
Hi again!

Just tried the =somfuntion(THIS) approach. It works somewhat. It does not work each time I open up a class in the class designer, might have something to do with caching. But it also works each time I set the property with it's own value again.

Here's a simple somefunction() to test it:
Code:
function somefunction()
   lparameters toControl
   ? toControl.Name
   Return ""
endfunc

I set the Tag property of a label class to =somefunction(THIS), and it printed the name of the label on the screen once. Then each time I reset the Tag property to =somefunction(THIS). But not each time I opened up the label class. In fact, althugh the function sets the tag to "" it stayed =somefunction(THIS) in the property window anyway.

As already said, I think this has to do with caching, but Clear all, Clear Class mylabel and Clear Classlib test.vcx didn't help me, to make that call occur once again, when opening up the class again.

Bye, Olaf.
 
Thank you Mike for your detailed explanation on how it possibly be doable. I will put some thoughts to it see if I can sneak in somehow.

Thanks Olaf for your input.

Your responses gave me some new ideas.

If successful, I will post my results.


Nasib Kalsi
 
A simple idea not based on passing THIS works easy. I set label captions to an expression like...
Code:
=translation(123)
...and can see at designtime, if german and english texts would fit the form design.

Source for the texts is a table with a language and text id, and the language id was set globally. Such simple things work great.

I played around by setting Height to =This.designresize("Height") and simply added the method designresize:
Code:
lparameters tcMember
RETURN GetPem(This,tcMember)

That had the effect, that even if I resized the control and saved changes, the next time the class was opened it reappeared with the old height. this seems to be an issue with baseclass.height and inheritance.

Bye, Olaf.
 
Did not realize that at design time the height,width changes. This is one good trick, and brings me closer to the solutions(?).

I am new to VFP, and learning everyday.

Thanks Olaf


Nasib Kalsi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top