Dynamically Add ModifiableObjects into DisplayArea

Hi All, I’m not happy to abuse of your help but since I’m an autodidact I really need any of your good hint about a question that’s pretty hard to me.

1* The Scope

I need to dynamically Append a series of dynamically created NewObject*n Into a DisplayArea. Each NewObjects holds a NewPicture as well as a NewText that are dinamically passed to the NewObjects at the moment of creation.

Actually I already do that adding CanvasObject into a CanvasContainer following the Example / ObjectsInCanvas / Provided by Xojo.

2* My Doubts

The Example / ObjectsInCanvas works really well for what concerns the dynamical creation / addiction / distruction / repositioning of the CanvasObject BUT it seems to limit me when I need for a deeper interaction with the NewObjects contents; for example when I need to change the Picture or even resize the Text the Object contains.

3* My Question to you

Should I really take in consideration the use of CanvasObject or I should be better figuring out the same implant stucture using ContainerControls instead of CanvasObjects?

Please remember I’m an autodidact if my question looks excessively stupid at your eyes but I feel like the ContainerControl gives to me the best chance to direclty interact with its contents, I’m wrong?

I think a ContainerControl would work best.

In order to figure out how the new implant should be set, do you know about an example like “Example/ObjectsInCanvas” I could consider as reference? I’m not sure I’m able to achieve the same behaviour I already got with the current approach after such a radical modify of the implant.

Also, can Containers be moved and dragged around a canvas on mouse drag event?

I’m now trying to understand if I should put a formatted container inside the dynamically drawed canvas or viceversa…

Very confused about all of that!

Dear God, no.

Do yourself one big favour and read “Expanding Objects - OOP makes enhancing software easy” on page48ff in xDev 12.5. In this beginner’s article Marc writes an object oriented drawing program, and it will really open your eyes to how to do it very easily. Nothing I’ve ever read helped me more.

See http://www.xdevmag.com/

Basically you define classes (like a rectangle, a picture, text, or a protein structure) that know how to draw themselves and react to mouse clicks (selection, moving, etc). It is sooo much easier than you think … and all the objects are simply stored as an array of the canvas, and you can add or remove them easily.

It sounds like an awesome solution and I can also remotely imagine how it could work now that you are describing it. If you got a minimal example to share with me, please do it, so that I can figure out how to unlock my code development at this crucial point.

Thank you for your input!

You can download the source code from xDev but here it is in my dropbox:

(Link replaced with better version from 2018 that works with newer Xojo)

1 Like

Thank you very much, I will take a look soon.

(Expecially for the adapted/newer version, you very gentle)

Sorry, forgot the graphics:

Tested in Xojo 2020 R2.1 and works fine

(btw this is the 2018 version from Marc Zeedar, so I didn’t adapt it, he did)

1 Like

And I thank you again Markus!

And a special encomium to the great work of Marc Zeedar! Kant is proud of you.

Awesome, this is even more than I was looking for!

You might also want to watch Marc’s video presentation from Xojo Connect 2018:

1 Like

Dear Markus, the SimpleDraw 2018 works as expected, extremely efficient!

Despite that I’m encountering difficulties when trying to directly access to the SpecificClassObject properties at once, without a particular object is selected, as I found no example cases in which it clearly happens.

Maybe you’ll agree to give me an extra tip on this.

// Remove Object Method, This method exploits the comparison of Objects() Positions.

Var j, Indexes(), Lefts() As Integer

// For All Objects Indexes

For j = ObjectList.LastRowIndex DownTo 0 Step 1
  // If Objects(index).Property = LastWordCanc << Here I'm encountering problems
  If Objects(j).Caption = LastWordCanc Then
    Indexes.Add j
    Lefts.Add Objects(j).Left
  End If

// Sort the matches according to the .Left property

Lefts.SortWith( Indexes() )

// Remove the one with the greatest value

ObjectList.Remove ( Indexes( Lefts.LastRowIndex ) )

MyDrawing.Remove( Indexes( Lefts.LastRowIndex ) )

Selection = -1


In the remote case someone is looking for this specific case based on SimpleDraw 2018 I found the way to directly access the property of a SomeTypeClassObject.

For j = ObjectList.LastRowIndex DownTo 0 Step 1

If SomeTypeClassObject(MyDrawing.Lookup(ObjectList(j), Nil)).TheCaption = LastWordCanc Then

// TheCaption is property of SomeTypeClassObject at the Index Value of Integer j

End If