# How do pass object type to a method?

**URL:** <https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137>\
**Category:** Getting Started\
**Created:** [June 9, 2014, 10:14am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137 "2014-06-09T10:14:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 9, 2014, 10:14am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/1 "2014-06-09T10:14:56Z")

</div>

I have a method that I want to be able to call and pass in the object type. For example:

```auto
myMethod(me)
```

In the method itself I then want to be able to do if statements and do things if the object is of different types e.g. label, text field, listbox etc.

I am guessing that I use “isA” in the if statement but I dont not what to put in the parameter for the method to store the type into? Should I use variant or something else?

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [June 9, 2014, 10:18am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/2 "2014-06-09T10:18:06Z")

</div>

How about “RectControl”? No variants please - these show your VB background 🙂

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 9, 2014, 10:22am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/3 "2014-06-09T10:22:34Z")

</div>

> [@97709:@Beatrix Willius](#):
>
> How about “RectControl”? No variants please - these show your VB background 🙂

Brilliant, just looked that up in the docs and it looks like what I need, yes I am showing my VB age!!! Thanks for the quick response.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [June 9, 2014, 11:43am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/4 "2014-06-09T11:43:12Z")

</div>

```auto
Class Window1

Inherits Window 

// Window1.passobj Method:

Protected Sub passobj(obj As Object) // <-- Example method receiving any kind of objects
   if obj isa PushButton then
      msgbox "Received a Push Button: "+PushButton(obj).Name
   End If
End Sub

// Window1 Control PushButton1:

Sub Action()
   passobj(me)
End Sub

End Class
```

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 9, 2014, 11:49am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/5 "2014-06-09T11:49:30Z")

</div>

Thanks Rick that is exactly what I was after.

---

<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:** [June 9, 2014, 3:13pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/6 "2014-06-09T15:13:31Z")

</div>

The other option is to create an interface, and then make subclasses of the controls and have them implement the interface

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 9, 2014, 8:23pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/7 "2014-06-09T20:23:28Z")

</div>

> [@97820:@Norman Palardy](#):
>
> The other option is to create an interface, and then make subclasses of the controls and have them implement the interface

Now you have just totally blown my head!!! I have just got my head around classes and oops and when I started to read about interfaces and how you can make things have multiple faces with the same thing I decided I would leave that part of the book until a later stage 😉 By the way, great book called Demystifying OOPs explains the whole OOPs thing in a very simple way and the book is non language specific and a really easy read for anyone new to OOPs.

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 9, 2014, 8:25pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/8 "2014-06-09T20:25:17Z")

</div>

I case anyone is interested: [Amazon](http://www.amazon.co.uk/gp/product/B005XM6OUA/ref=oh_d __o05_details_o05__ i00?ie=UTF8&psc=1)

---

<div class="post-metadata">

**Author:** ![Harrie\_Westphal](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Harrie\_Westphal](https://forum.xojo.com/u/Harrie_Westphal)\
**Post date:** [June 10, 2014, 6:47pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/9 "2014-06-10T18:47:27Z")

</div>

Thanks for that second post, giving the Amazon location. I Googled the Demystifying OOPs, and much to my surprise the book didn’t appear, at least not on the first page of hits.

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 12, 2014, 8:56am UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/10 "2014-06-12T08:56:14Z")

</div>

The actual full name of the book is [OOP Demystified: A Self-teaching Guide](http://www.amazon.co.uk/gp/product/B005XM6OUA/ref=oh_d __o05_details_o05__ i00?ie=UTF8&psc=1)

---

<div class="post-metadata">

**Author:** ![Harrie\_Westphal](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Harrie\_Westphal](https://forum.xojo.com/u/Harrie_Westphal)\
**Post date:** [June 13, 2014, 4:46pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/11 "2014-06-13T16:46:12Z")

</div>

Yup, ordered the book and now have it in my possession. I’ve been programming for over close to 50 years and never with an OOPs language until going to RB back at version 1.1. I can achieve the things that I set out to do; but, it would be nice to more fully understand what some of you folks keep tossing out there in your replies. 😉

---

<div class="post-metadata">

**Author:** ![Nathan\_Wright](https://forum.xojo.com/user_avatar/forum.xojo.com/nathan_wright/32/575_2.png) [@Nathan\_Wright](https://forum.xojo.com/u/Nathan_Wright)\
**Post date:** [June 13, 2014, 4:54pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/12 "2014-06-13T16:54:00Z")

</div>

What I toss out in my replies is total gibberish but everyone else seems to understand OOPs and talks so highly about it I thought I should try and get to grips with it. This book is really easy to grasp how and why it should be used and is written in chunks that make it easy to read a bit and then go an try it in Xojo, then go back and read a bit more. You feel like you are getting somewhere. Gook luck with the book, I hope you find it as useful as I do.

---

<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:15pm UTC](https://forum.xojo.com/t/how-do-pass-object-type-to-a-method/17137/13 "2020-10-29T17:15:44Z")

</div>


