# Does method exist ?

**URL:** <https://forum.xojo.com/t/does-method-exist/19419>\
**Category:** General\
**Created:** [September 23, 2014, 9:18am UTC](https://forum.xojo.com/t/does-method-exist/19419 "2014-09-23T09:18:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 23, 2014, 9:18am UTC](https://forum.xojo.com/t/does-method-exist/19419/1 "2014-09-23T09:18:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 23, 2014, 9:37am UTC](https://forum.xojo.com/t/does-method-exist/19419/2 "2014-09-23T09:37:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 23, 2014, 9:40am UTC](https://forum.xojo.com/t/does-method-exist/19419/3 "2014-09-23T09:40:37Z")

</div>

thank’s Christian

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 23, 2014, 3:06pm UTC](https://forum.xojo.com/t/does-method-exist/19419/4 "2014-09-23T15:06:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 23, 2014, 3:09pm UTC](https://forum.xojo.com/t/does-method-exist/19419/5 "2014-09-23T15:09:13Z")

</div>

sorry, no way.

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

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 23, 2014, 3:18pm UTC](https://forum.xojo.com/t/does-method-exist/19419/6 "2014-09-23T15:18:35Z")

</div>

and how can I do that ?

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [September 23, 2014, 3:19pm UTC](https://forum.xojo.com/t/does-method-exist/19419/7 "2014-09-23T15:19:02Z")

</div>

[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)

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 23, 2014, 3:23pm UTC](https://forum.xojo.com/t/does-method-exist/19419/8 "2014-09-23T15:23:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [September 23, 2014, 3:50pm UTC](https://forum.xojo.com/t/does-method-exist/19419/9 "2014-09-23T15:50:18Z")

</div>

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](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

```auto
     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

```auto
   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

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 25, 2014, 9:00am UTC](https://forum.xojo.com/t/does-method-exist/19419/10 "2014-09-25T09:00:31Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Will\_Shank](https://forum.xojo.com/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@Will\_Shank](https://forum.xojo.com/u/Will_Shank)\
**Post date:** [September 25, 2014, 10:09am UTC](https://forum.xojo.com/t/does-method-exist/19419/11 "2014-09-25T10:09:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johann\_Kienbrandt](https://forum.xojo.com/user_avatar/forum.xojo.com/johann_kienbrandt/32/2528_2.png) [@Johann\_Kienbrandt](https://forum.xojo.com/u/Johann_Kienbrandt)\
**Post date:** [September 25, 2014, 2:26pm UTC](https://forum.xojo.com/t/does-method-exist/19419/12 "2014-09-25T14:26:30Z")

</div>

thanks Will

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:25pm UTC](https://forum.xojo.com/t/does-method-exist/19419/13 "2020-10-29T17:25:40Z")

</div>


