REAL Software Forums

The forum for REAL Studio and other REAL Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 02, 2010 9:22 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Does RB have the CallByName function
PostPosted: Thu Jul 30, 2009 6:42 am 
Offline

Joined: Thu Jul 30, 2009 6:30 am
Posts: 15
VB6 had a terrific function called 'CallByName' which allowed runtime calls to any objects methods or properties using a string literal. Does RB have this or an equivalent?

regards,
Chris Benton


Top
 Profile E-mail  
 
 Post subject: Re: Does RB have the CallByName function
PostPosted: Thu Jul 30, 2009 10:16 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1098
Well, you can always call an object or a class's method with
someClass.someMethod
but only if the "someMethod" is made Public at design time.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
 
 Post subject: Re: Does RB have the CallByName function
PostPosted: Wed Aug 26, 2009 9:25 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 9:35 am
Posts: 535
Location: South Portland, Maine
Chris Benton wrote:
VB6 had a terrific function called 'CallByName' which allowed runtime calls to any objects methods or properties using a string literal. Does RB have this or an equivalent?

There is no CallByName function in REALbasic but you can pretty much do this using either RBScript or Introspection.

To call a method on a class using RBScript:

Code:
Dim script As New RBScript
script.Context = Self
script.Source = "MyMethod"
script.Run


Doing this with introspection is trickier. You'll have to loop through the methods on the class and then call the one you want:

Code:
  Dim info As Introspection.TypeInfo
 
  info = Introspection.GetType(Self)
 
  Dim methods() As Introspection.MethodInfo
  methods = info.GetMethods
 
  For Each m As Introspection.MethodInfo In methods
    Dim param() As Variant
    Dim rv As Variant
   
    If m.Name = "MyMethod" Then
      Try
        rv = m.Invoke(Self, param)
      Catch e As RuntimeException
        Dim eInfo As Introspection.TypeInfo
        eInfo = Introspection.GetType(e)
       
        Dim eMessage As String
        eMessage = "A " + eInfo.FullName + " occurred and was caught."
        If e.Message <> "" Then
          eMessage = eMessage + EndOfLine + "Message: " + e.Message
        End If
      End Try
     
    End If
   
  Next

_________________
Paul Lefebvre
LogicalVue Software, Inc. --- Software Made Simple Blog --- RBDevZone --- RBDevZone Podcast --- Association of RB Professionals


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group