Does method exist ?

I have a window with a few container controls.
How can I find out if a certain method exists in any container control ?

keep references to containers in arrays, so you can access them later.

thank’s Christian

I declared a handle as integer property as myHandle,
loaded as: myHandle = containerControl.handle

and now how can I call a method of this handle ?

myHandle.function_name does not work

sorry, no way.

You need to keep variables with references to the containers to access them.

and how can I do that ?

[quote=131166:@Johann JFK]I have a window with a few container controls.
How can I find out if a certain method exists in any container control ?[/quote]

Dont
One of
Idea #1

  1. Make an interface
  2. have all the containers that you need to interact with in a specific way implement this interface
  3. keep track of the containers (since they do not show up in the control list for the window)
  4. then you can check is a container is one of the interface types using ISA

Idea #2

  1. make a container control - this is the superclass for ALL these containers
  2. then each of you new containers subclasses this so they can override the methods
  3. you still need to keep a list & check if the container is one of these type (using ISA)

Norman, that sounds very complicated to me, I will try but that can take,
thanks

Well its not any more complex than trying to see IF a container control contains a method.
To do that you will still need the list of containers.
Then you will have to use introspection to find all the methods that container control implements & find the right one & then invoke it.

Interfaces are actually REALLY easy
They are quite literally a promise that if I say I am a “Thing that implements the interface Foo then I have ALL the methods that the interface Foo defined”
Thats it

So if you look in the LR there are two interfaces you can look at - Readable & Writable
http://documentation.xojo.com/index.php/Readable
Readable is quite simple - anything that implements READABLE will have the 3 methods defined in the READABLE interface.
EOF, READ, and READERROR
The interface DOESN"T implement the methods - it just sets out the API

So lets go over something really quickly
Work in a new project (desktop)
Add a new new interface - Beeper
To that interface add two methods

  • CanBeep() as Boolean
  • Beep()

Thats it for the interface

Now lets add a few classes that implement this
Add a Class - frog
Then in the inspector click the “interfaces” button & select “Beeper”
All the methods will be added - all you need to do is add code to them

[code]Class Frog
Implements Beeper
Function CanBeep() as boolean
return true
end function

  Sub Beep()
          msgbox "frog beeping"
  end sub

[/code]
Do the same for a new Class - Car

[code]Class Car
Implements Beeper
Function CanBeep() as boolean
return false
end function

  Sub Beep()
          // we do nothing because we don't beep
  end sub[/code]

OK now lets put this to the test
Edit Window1’s open event
Lets create a “list” of instances to test with - we don’t need a bunch
Then we’ll see how to use them

     dim list() as Beeper

     list.append new Frog 
     list.append new Car

OK so this works because when you say “class X implements interface Y” then that class ISA Y
So a frog isa beeper and a car isa beeper (because we said they implement the interface)
Continue adding code

   for each bp as Beeper in list
          if bp isA Beeper then // we know this is true but JUST  to show this works
             if bp.CanBeep then bp.Beep
          end if
    next

Notice that in this code we don’t have to know something is a frog or car - all we care about is that they are a beeper then we can be sure we can call the methods that interface implements & we’re good to go

Classes, including container controls, can implement as many interfaces as you need

thanks Norman for the example, I probably have to rethink my problem.
I could not find a way in a new project to create a new interface, how can I do it ?

In the menubar select Insert > Class Interface. It’s 3 down.

thanks Will