On Aug 22, 2006, at 9:18 AM, Jan Erik Moström wrote:

I was playing around a bit and I'm glad to say that I can defined methods like
this:

Sub set(name as String, assigns value as String)
Sub set(name as String, assigns value as Integer)
Function get(name as String) As String
Function get(name as String) As Integer

but then I run into trouble when I want to use them

  dim i as Integer
  dim s as String

  p.set("hello") = 5
  p.set("piff")  = "Hejsan"

That works just fine, but unfortunately this doesn't work

  i = p.get("hello")
  s = p.get("piff")

I get a message like this for each of the last two lines "There are several items with this name and it is not clear which one the call refers to".

Is there some way I can get RB to recognize that the expected return type? Is
there some way I can get this to work?

You can write one method like this:

    Function get(name as String) As Variant

Which is a "loose" type variable which will attempt to convert the return value into the fixed variable type (string, integer, etc). Variants are the same variables used by REALbasic in the Dictionary and other similar classes. There are a few disadvantages, but there are a number of advantages too. Look up Variant in the Language Reference, and to tell what Type of data the variant stores, lookup Variant.Type() and VarType.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to