Post #155,961
5/19/04 4:45:47 PM
|
VB.Net, C# and Delphi are the same way
Though Delphi seems to copy the event procedure name, but that means you have 2 controls calling the same event, not 2 copies of the code. I'm not sure why you'd want either most of the time. With all of the above, the event procedure is a member of the containing form class.
-- Chris Altmann
|
Post #155,973
5/19/04 5:27:58 PM
|
I'm not sure I see where you're going...
With Delphi (and all the Builder/Kylix-type compilers) The behavior you describe is correct, but there is at least one good use for this capability. I may have several controls on a form whose event needs to be handled in the same way. Having this capability has seved me much work over Access VBA, where you have to copy the actual event code from one event handler to another (to another (to another...)).
I do not see why you would object (v.t., not a noun ;-) ) to this behavior.
jb4 shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT
|
Post #155,985
5/19/04 6:30:22 PM
|
Re: I'm not sure I see where you're going...
Make your event handlers call a single function that performs the common functionality. You still have to wire up the event for each copied control, and Delphi's behavior might help there, but how often do you call the exact same code from multiple controls of the same type (there are other mechanisims for toolbar/menu duality)? You'll at least want to pass in different parameters or pull in information from a different set of other controls. Where do you put that code?
I guess what you and jbrabeck describe would save one extra copy/paste per copied control, but at the cost of having to erase that code for every control where you just wanted to duplicate the control's properties (ie: a row of buttons with the same size/color/etc).
Also, I didn't check earler, but in Access if you put an expression (ie: "=DoStuff" where DoStuff is a Sub containing your common code), in an Control's event property and copy that control, the text in the event property will copy much like Delphi's behavior.
-- Chris Altmann
|
Post #156,071
5/20/04 1:28:31 PM
|
It's actually quite useful
at least for those of us who do I/O screens: you have a big bunch of buttons to control outputs. The button event should do the exact same thing (turn on an output on the motion controller / PLC / whatever); the only thing that changes is the output bit number.
VB6 Control Arrays work quite nicely for this, but the BCB/Delphi VCL wire many controls to one event handler approach also works well.
The even better approach, which I currently use in Tkinter, is to create all the controls from a mini-database (MetaKit) so adding another output or input is simply a matter of adding another line to the database. That's much better than futzing around with VB GUI screen designer. Still, all the Tkinter output buttons use a common command handler.
Tony
|
Post #156,104
5/20/04 3:51:01 PM
|
You can do that in VB...
...that is, create and destroy buttons/textboxes/whatever on the fly.
At least in VB6 you can. Dunno about earlier versions.
Tired of lying in the sunshine staying home to watch the rain. You are young and life is long and there is time to kill today. And then one day you find ten years have got behind you. No one told you when to run, you missed the starting gun.
|
Post #156,123
5/20/04 5:03:50 PM
|
Yes, you can, but....
very few people do. And, the support isn't as good as in systems designed for this (Tk, wxWindows, Swing, etc). For example, you don't have good layout managers in VB6.
That's one reason why it's good to learn different languages. After learning Python & Tkinter (plus a little wxPython), when I have to program in VB.nyet (like it looks like I'll be doing soon for a project), I will be be programming differently than I would have a couple of years ago.
Tk has pretty decent layout managers; I can get the layout I want without too much effort. wxWindows seems a little more primitive (but does have a lot of other advantages over Tk). I haven't used Java's Swing. For VB.nyet, I'll probably write my own; MSDN actually has an article on doing it.
Another technique I'll probably use is using a scripting language for flexibility. You can still do this in .nyet (or use class loader), but MS doesn't emphasize it and so most people never think about it....unless you have a scripting background.
Tony
|
Post #156,127
5/20/04 5:33:48 PM
|
Quite aware of that situation.
I've done GUI app development (in an educational context only) in Java via Swing, VB, VC++, and VC#. Of all of the methods for layout, Swing freaked me out having such a different way of handling controls. I'm so used to the idea of fixed pixel points that having something like that kinda overwhelms me. The .Nyet interface has some limited Swing-like mapping options, but not many that I've seen so far.
Probably should give some of those others a shot one of these days.
Tired of lying in the sunshine staying home to watch the rain. You are young and life is long and there is time to kill today. And then one day you find ten years have got behind you. No one told you when to run, you missed the starting gun.
|
Post #156,137
5/20/04 7:10:36 PM
|
It's worth checking out
The idea also works very nicely for program configuration dialogs. I use Metakit to store the info (and have the Python class automatically create the class variables from the database).
I'm pretty sure there are open source projects out there with a similar approach, but using XML -- basically creating a UI specified by an XML file.
I've heard that some of the Swing layout managers are hard to grasp. You might want to look at John Grayson's Python and Tkinter Programming book; he does some very interesting things with Tkinter.
Tony
|