Xojo 2022 r2 Delegate Tutorial - video and code

Had a colleague ask me to explain a delegate. Answered him with a video and code from scratch. A simple stick-person is drawn to show the Object-Oriented-Programming in this advanced topic.

Step-by-step instructions are shown in the YouTube Video, and code can be downloaded at Github Delegate 2022

8 Likes

Nicely done!

Hi Eugene. This looks good. I follow you on twitter, and would be glad to like and retweet.

I watched it yesterday. Thanks for sharing!

I feel a bit ‘Emperors new clothes’ here …I don’t get it.
The delegate doesn’t seem to add any functionality, just apparently redundant code?

Having created

DrawHead(g as graphics)

you can already do this:

var p as new picture (200,200)
call DrawHead(p.graphics)

Why create a delegate?
Why mess about with address and .invoke()

1 Like

It was obviously a simplistic and contrived application, designed solely to demonstrate how to create and invoke a delegate. An app that actually solved a problem requiring the use of delegates would be way to involved for a tutorial. I think this was simple and to the point. Well done, Eugene!

Hi @Jeff_Tullin,

You are completely correct that this is too-much coding for a smaller project and smaller program. When the program starts to become larger, then the complexity of non-OOP becomes difficult. The point is to explain how OOP Delegates worked.

An example would be building a robot, which has touch sensors, legs, arms, head, body, a sensor to keep the body upright. This type of project would likely require a group of programmers. To make it easier to determine that there is an issue with the arm algorithm, where the robot squeezes a glass too hard and the glass breaks, the programmer could look in the touch sensor algorithm and not worry about the legs, head, and possibly look at the arm algorithm.

Since the code is an object, adding or removing an arm would be easier than going through the interlaced code.

As Tim mentioned, its just a simple program to understand the concept - thats all :slight_smile:

I guess what I’m asking is ‘what use is a delegate’ rather than ‘what use is this demo’?
I’ll switch that question to a new topic.

Hello @Arthur_Couture,

Glad you mentioned twitter, as I honestly forgot. I’ll create a tweet, and thanks for the suggestion!