dynamic form creation

I'm toying with some ideas for driving our user interface with XML files, similar to Mozilla's XUL. It appears, however, that I've run into a major limitation of VB6.

[code]
Private WithEvents objTextbox As TextBox

Private Sub Form_Load()

Load Me.Text1(1)
Set objTextbox = Me.Text1(1)
With objTextbox
.Move 0, 0
.Visible = True
End With

End Sub

Private Sub objTextbox_Change()

Debug.Print objTextbox.Text

End Sub
[/code]

The "Set objTextbox = Me.Text1(1)" statement pukes because VB is unable to match the events of an element of a control array to a variable declared WithEvents as the same type of that array's elements.

Major suckage.


[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

[code]
$ select * from users where clue > 0
no rows returned
[/code]

Comments

  • : I'm toying with some ideas for driving our user interface with XML files, similar to Mozilla's XUL. It appears, however, that I've run into a major limitation of VB6.
    :
    : [code]
    : Private WithEvents objTextbox As TextBox
    :
    : Private Sub Form_Load()
    :
    : Load Me.Text1(1)
    : Set objTextbox = Me.Text1(1)
    : With objTextbox
    : .Move 0, 0
    : .Visible = True
    : End With
    :
    : End Sub
    :
    : Private Sub objTextbox_Change()
    :
    : Debug.Print objTextbox.Text
    :
    : End Sub
    : [/code]
    :
    : The "Set objTextbox = Me.Text1(1)" statement pukes because VB is unable to match the events of an element of a control array to a variable declared WithEvents as the same type of that array's elements.
    :
    : Major suckage.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :

    See this is where VB.NET shines, but I'm sure that is not an option :)Look at it this way, we can all curse at Microsoft together, it has become a ritual at my work (freaken source safe grrr.) Well good luck.


  • : : I'm toying with some ideas for driving our user interface with XML files, similar to Mozilla's XUL. It appears, however, that I've run into a major limitation of VB6.
    : :
    : : [code]
    : : Private WithEvents objTextbox As TextBox
    : :
    : : Private Sub Form_Load()
    : :
    : : Load Me.Text1(1)
    : : Set objTextbox = Me.Text1(1)
    : : With objTextbox
    : : .Move 0, 0
    : : .Visible = True
    : : End With
    : :
    : : End Sub
    : :
    : : Private Sub objTextbox_Change()
    : :
    : : Debug.Print objTextbox.Text
    : :
    : : End Sub
    : : [/code]
    : :
    : : The "Set objTextbox = Me.Text1(1)" statement pukes because VB is unable to match the events of an element of a control array to a variable declared WithEvents as the same type of that array's elements.
    : :
    : : Major suckage.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    :
    : See this is where VB.NET shines, but I'm sure that is not an option :)Look at it this way, we can all curse at Microsoft together, it has become a ritual at my work (freaken source safe grrr.) Well good luck.

    Ironically enough, while I was trying to prove this concept, I overheard our lead developer talking to the project manager about the need to start looking at converting to .NET (among other things). So I'm now installing the framework and SDK to see if I can get a leg up on everyone else and demonstrate a more dynamic XML-driven GUI by the time she gets around to looking at conversion.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Ok, I've got the framework installed and the SDK installed. Where the hell are the compilers hiding?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : Ok, I've got the framework installed and the SDK installed. Where the hell are the compilers hiding?

    Nevermind. Found them under C:WINNTMicrosoft.NET

    *sigh* Here I go through the gates of Hell.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • I must be missing something.

    Why not just do:

    Text1(1).Top = 0
    Text1(1).Left = 0

    Instead of all that object stuff?






    [purple]Melissa[/purple]

  • : : Ok, I've got the framework installed and the SDK installed. Where the hell are the compilers hiding?
    :
    : Nevermind. Found them under C:WINNTMicrosoft.NET
    :
    : *sigh* Here I go through the gates of Hell.
    :
    If you're gonna do .NET, I suggest C#.NET. It's a MUCH better language than VB.NET and you have to re-learn much stuff anyway (VB.NET is kinda different to VB)... That or see how the Python.NET compiler is coming along. ;-) Last I heard it was doing well, but mapping a dynamic language onto a VM for static languages is going to hit some performance issues at some point so if you're doing what I guess you'd call the powerful Python stuff, it may be slower than "normal" Python.

    If you don't want to fork out for VisualStudio.NET, then there's always #develop freely available from:-
    http://www.icsharpcode.com/

    Supports VB.NET and C#.NET syntax highlighting, has a form designer, etc.

    Have fun,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : I must be missing something.
    :
    : Why not just do:
    :
    : Text1(1).Top = 0
    : Text1(1).Left = 0
    :
    : Instead of all that object stuff?
    :
    :
    :
    :
    :
    :
    : [purple]Melissa[/purple]
    :
    :

    I believe Infidel wants to to be able to trap events with the modularly assigned variable. Making simple property assignments above just does not cut it.
    ------------------------------------------------------------------------

    Infidel: You aren't going to believe this but I got this paragraph from a VB6 book (by Franscesco Balena):

    "There's an undocumented bug in how Visual Basic implements the WithEvents keyword: you can't use WithEvents with controls that belong to a control array:"

    [code]
    Dim WithEvents TextBox As TextBox
    Private Sub Form_Load()
    ' Raises a Type Mismatch run-time error.
    Set TextBox = Text1(0)
    End Sub
    [/code]

    "This bug prevents you from dynamically creating a new control from a control array and then trapping its events using multicasting. Unfortunately, there isn't any known solution to this problem. Curiously, this bug doesn't manifest itself if the control you're assigning to a WithEvents variable is an ActiveX control authored in Visual Basic."

    Well cheers. Good Luck with VB.NET. Let me know if you need help. As for C#, yes it is a more powerful language, but nothing beats learning the .NET Framework if yo already know Visual Basic. Also C# is not much more powerful, so those extra features probably would be rarely needed on beginning projects. The only added features I can think of, that C# has over VB.NET, is operator overloading and using C++ like pointers in unsafe sections. C# will also support code templating in its second incarnation. Otherwise it aint much better. Heck it compiles basically to the same Intermediate Language.


  • : If you're gonna do .NET, I suggest C#.NET. It's a MUCH better language than VB.NET and you have to re-learn much stuff anyway (VB.NET is kinda different to VB)...

    Yeah, I know. It's not my call, though. I keep hyping python and they look at me like I'm a raving lunatic.

    : That or see how the Python.NET compiler is coming along. ;-) Last I heard it was doing well,

    Depends on whose version you read about. The "original" attempt by Mark Hammond (who created the fabulous win32 extension modules for python) ran into some issues he couldn't resolve. I've seen a few mentions of a separate project that claimed major successes so I don't know which is which.

    :but mapping a dynamic language onto a VM for static languages is going to hit some performance issues at some point so if you're doing what I guess you'd call the powerful Python stuff, it may be slower than "normal" Python.

    Depends, I guess, on how well python concepts translate into .NET concepts.

    : If you don't want to fork out for VisualStudio.NET, then there's always #develop freely available from:-
    : http://www.icsharpcode.com/

    Sweet, I'll give that a look.

    Thanks.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : "This bug prevents you from dynamically creating a new control from a control array and then trapping its events using multicasting. Unfortunately, there isn't any known solution to this problem. Curiously, this bug doesn't manifest itself if the control you're assigning to a WithEvents variable is an ActiveX control authored in Visual Basic."

    Well, don't see why he's saying there's no solution. Why not just create an ActiveX control in VB which simply contains the control you need? Extra stuff to distribute, but an easy fix.


    [purple]Melissa[/purple]

  • : : "This bug prevents you from dynamically creating a new control from a control array and then trapping its events using multicasting. Unfortunately, there isn't any known solution to this problem. Curiously, this bug doesn't manifest itself if the control you're assigning to a WithEvents variable is an ActiveX control authored in Visual Basic."
    :
    : Well, don't see why he's saying there's no solution. Why not just create an ActiveX control in VB which simply contains the control you need? Extra stuff to distribute, but an easy fix.

    Yeah, easy, but more work. Boring, tedious work. You've got to create a whole control project just to wrap an intrinsic control, meaning you'll have to duplicate all the methods, properties and events you might ever need. Ugh.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : I must be missing something.
    :
    : Why not just do:
    :
    : Text1(1).Top = 0
    : Text1(1).Left = 0
    :
    : Instead of all that object stuff?

    It was an idea I had to dynamically generate forms containing controls with common functionality in classes rather than in ActiveX controls. Oh well.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : : If you're gonna do .NET, I suggest C#.NET. It's a MUCH better
    : : language than VB.NET and you have to re-learn much stuff anyway
    : : (VB.NET is kinda different to VB)...
    :
    : Yeah, I know. It's not my call, though. I keep hyping python and
    : they look at me like I'm a raving lunatic.
    :
    *sighs* I'm in a position where thankfully I can write stuff in my languages of choice a lot of the time - if you're organisation is stuck into VB, I guess that's the way things are. :-( I guess it's easier to find VB programmers than it is to find Python ones. OTOH, I imagine the average for-hire Python programmer is going to be a better programmer than the average VB one. Not that there aren't some very skilled VB programmers out there (heck, I just look at this board and I see some of them).

    : : That or see how the Python.NET compiler is coming along. ;-)
    : : Last I heard it was doing well,
    :
    : Depends on whose version you read about. The "original" attempt by
    : Mark Hammond (who created the fabulous win32 extension modules for
    : python) ran into some issues he couldn't resolve. I've seen a few
    : mentions of a separate project that claimed major successes so I
    : don't know which is which.
    :
    I think the one I saw was being done by someone involved with the Mono project.

    : : but mapping a dynamic language onto a VM for static languages is
    : : going to hit some performance issues at some point so if you're
    : : doing what I guess you'd call the powerful Python stuff, it may be
    : : slower than "normal" Python.
    :
    : Depends, I guess, on how well python concepts translate into .NET
    : concepts.
    :
    I'm (very minorly) involved with Parrot development - minor as in I've provided the odd patch to fix some stuff that's broken (mostly on Win32), reported problems, provided an example of calling into the Win32 API from Parrot and started working on a Win32 library. The Mono guys have been showing off benchmarks for how fast they can get Python doing some things on .NET, though according to the lead Parrot developer (who's opinion tends to be pretty close the the truth) once they start implementing certain things that won't translate well to .NET concepts, it's really going to slow things down. Parrot is designed from the ground up for dynamic languages like Perl, Python, Ruby etc.

    At OSCON this year there is to be a standard Python/Parrot Python performance competition. I believe the bet involves whipped cream and certain people's faces.

    : : If you don't want to fork out for VisualStudio.NET, then there's
    : : always #develop freely available from:-
    : : http://www.icsharpcode.com/
    :
    : Sweet, I'll give that a look.
    :
    : Thanks.
    :
    Welcome. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : : : That or see how the Python.NET compiler is coming along. ;-)
    : : : Last I heard it was doing well,
    : :
    : : Depends on whose version you read about. The "original" attempt by
    : : Mark Hammond (who created the fabulous win32 extension modules for
    : : python) ran into some issues he couldn't resolve. I've seen a few
    : : mentions of a separate project that claimed major successes so I
    : : don't know which is which.
    : :
    : I think the one I saw was being done by someone involved with the Mono project.

    Yeah, ok, that rings a bell. Sounded like they were making real progress there. I'll have to look in to it.

    : : Depends, I guess, on how well python concepts translate into .NET
    : : concepts.
    : :
    : I'm (very minorly) involved with Parrot development - minor as in I've provided the odd patch to fix some stuff that's broken (mostly on Win32), reported problems, provided an example of calling into the Win32 API from Parrot and started working on a Win32 library. The Mono guys have been showing off benchmarks for how fast they can get Python doing some things on .NET, though according to the lead Parrot developer (who's opinion tends to be pretty close the the truth) once they start implementing certain things that won't translate well to .NET concepts, it's really going to slow things down. Parrot is designed from the ground up for dynamic languages like Perl, Python, Ruby etc.

    It'll be interesting to see what .NET is capable of from a Pythonic POV.

    : At OSCON this year there is to be a standard Python/Parrot Python performance competition. I believe the bet involves whipped cream and certain people's faces.

    I read about that on Guido's blog. That would be something to see!




    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • [b][red]This message was edited by Moderator at 2004-1-21 21:43:18[/red][/b][hr]
    : Well, don't see why he's saying there's no solution. Why not just create an ActiveX control in VB which simply contains the control you need? Extra stuff to distribute, but an easy fix.
    :

    Maybe, just maybe, I have a solution:

    Add a usercontrol to your project. Add the dynamic controls to the usercontrol (a textbox, a picturebox, etc.). Add the usercontrol to your form as an array. Map the required control-properties to the usrcontrol's properties (in all _Click events, use RaiseEvent Click, etc.). Add an extra property to tell the usercontrol which control to bring to the front and enable.

    Ta-da! You can do this:

    [code]Load DynControl(1)
    DynControl.ControlType = "TextBox"
    [/code]

    All the events will pass through your indexed event handler and you don't have a WithEvents issue.

    -or-

    Use the control to return an unindexed version of a control and set it to the WithEvents'ed control:

    [code]Public WithEvents txtObj As TextBox
    ......
    Load DynControl(1)
    Set txtObj = DynControl.ReturnControl("TextBox")
    [/code]

    Good luck and Hope This Helps!
    KDL


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories