Object handling for dummies

Posted by goo on 02-Feb-2017 01:06


I would like to understand a bit more of classes. Could anyone explain the following:

Normally I would do it like this when I add a button to a Telerik grid, like static, but now I want to do this more dynamic:

So how do I create the anchorstyle and the button in a dynamic way, like create button..... ? Can I make a static class, and store the result in a temp-table ? Or should I do it with a extent parameter? I am strugling understand this conspet :-)


DEFINE PRIVATE VARIABLE button1 AS System.Windows.Forms.Button NO-UNDO.

DEFINE VARIABLE nestedvar1 AS System.Windows.Forms.AnchorStyles NO-UNDO.

nestedvar1 = CAST(Progress.Util.EnumHelper:Or(CAST(Progress.Util.EnumHelper:Or(System.Windows.Forms.AnchorStyles:Top, System.Windows.Forms.AnchorStyles:Bottom), System.Windows.Forms.AnchorStyles), System.Windows.Forms.AnchorStyles:Left), System.Windows.Forms.AnchorStyles).

THIS-OBJECT:button1:Anchor = CAST(Progress.Util.EnumHelper:Or(nestedvar1, System.Windows.Forms.AnchorStyles:Right), System.Windows.Forms.AnchorStyles).
THIS-OBJECT:button1:FlatStyle = System.Windows.Forms.FlatStyle:Flat.
THIS-OBJECT:button1:Image = CAST(resources:GetObject("button1.Image"), System.Drawing.Image).
THIS-OBJECT:button1:ImageAlign = System.Drawing.ContentAlignment:TopLeft.
THIS-OBJECT:button1:Location = NEW System.Drawing.Point(195, 3).
THIS-OBJECT:button1:Name = "button1".
THIS-OBJECT:button1:Size = NEW System.Drawing.Size(186, 54).
THIS-OBJECT:button1:TabIndex = 0.
THIS-OBJECT:button1:Text = "button1".
THIS-OBJECT:button1:UseCompatibleTextRendering = TRUE.
THIS-OBJECT:button1:UseVisualStyleBackColor = TRUE.

All Replies

Posted by Brian K. Maher on 02-Feb-2017 05:40

If you want a standardized control you may want to create either user controls or abl inherited controls and have custom code or constructors that build the object the way you need it built then just add it to the form.  In the following code I created an ABL Inherited Control that unhers from UltraButton.  I dropped one instance onto a form statically then in that buttons click event I did this:
       METHOD PRIVATE VOID myUltraButton1_Click( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):
        DEFINE VARIABLE x AS MyUltraButton.
        x = NEW MyUltraButton().
        x:Location = NEW System.Drawing.Point(150, 150).
        x:Name = "x".
        x:Size = NEW System.Drawing.Size(150, 23).
        x:TabIndex = 1.
        x:Text = "New myUltraButton1".
       END METHOD.
I’m sure others will chime in with many varied ways to accomplish this.  Mine is just a very simple instance that doesn’t play around with anchors or anything.

Posted by goo on 02-Feb-2017 07:40

But I would like to build i.e. n number of buttons, with 1 event that checks i.e. the name of the button to do a special thing. The thing I kind of not sure of, is what to do with the classes that will be overwritten for each button.

I have been thinking making a variable button as class ..... extent. Then find what number of buttons that will be created, and with that do a extent(...) = number of buttons. Then I will be able to store all buttonclass...

Is that a good way of doing it?

Posted by Brian K. Maher on 02-Feb-2017 07:46

You could do it that way, but why bother?  Once the object is added to the controls collection with THIS-OBJECT:Controls:Add(x) it will hang around.  In the event handler, you will have a reference to the object that generated the event so you could just check its :Name or :Text atrribute and do whatever you need to do.

Posted by Brian K. Maher on 02-Feb-2017 07:50

One other thing ... it may not be obvious but all of what you consider the “static” objects (i.e. dragged & dropped in the Visual Designer) are actually objects that are being dynamically created at runtime in the InitializeComponent() method so you can basically copy an objects initialization code into some other method, make a few tweaks, add it the the Controls collection and call that method at runtime to instantiate more instances.

Posted by goo on 02-Feb-2017 08:10

Thanks Brian, ok, so I really don't need to store the class... nice to know.

This thread is closed