Qbasicnews.com

Full Version: CallByName?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there such a function in FB? In VB6, you can call a function by passing a string to CallByName. Is this possible in FB?
TheAdventMaster: In that example the sub/function name isn't in a string...

Torahteen: AFAIK that is not possible, but you could set up an
array with sub names and their pointers

Pseudocode:
Code:
type subListEntry
  name as string
  p as functionpointer
end type

dim shared subList(0 to ?) as subListEntry

sub init_sub_list
  subList(0).name="sub0"
  subList(0).p=@sub0
  subList(1).name="sub1"
  subList(1).p=@sub1
  ...
end sub

sub call_a_sub(sname as string,parameters)
  for n=0 to ?
    if subList.name=sname then
      @subList.p parameters
      exit sub
    end if
  next
end sub

Anonymous

yeah, like red_Marvin said.

a hash table with function pointers would be the way to go.

Anonymous