Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Frank Brübach on January 30, 2025, 11:17:20 PM

Title: Static function Link example
Post by: Frank Brübach on January 30, 2025, 11:17:20 PM

thanks for your update charles, made this example to check and it's running fine,
you dont need at all the type block with declare functions.
second: you can change the static function with the link llike below, both ways are running ;)
regards, nice weekend, frank

'
' test o2 static function with link, 30-01-2025
'
'-------------------------------------------------------------------------------
declare function ptr myBatman(int x) as int 'our interface function

'
type abc
  'dim as int mi                'property
  'declare function f1() as int 'method
  'declare static function f2(int n) as int ' go
  'declare function f4(int n) as int 'method

end type

methods of abc
==============

dim static pp as int

' both static functions works

'static function f4(int x) as int,link @myBatman ' 1) linking to the outer function

static function f4(int x) link @myBatman as int ' 2) linking to the outer function

  pp=x
  print "f4 " x
end function

'function f1() as int
'  print "f1 " pp
'end function
'
end methods

myBatman(1357911)

' ends
['code]
Title: Re: Static function Link Interface Inner...
Post by: Frank Brübach on February 01, 2025, 09:09:25 PM

'
 hey charles, I have done a new example with static function like my first issue
 works also very well
'
'
==========
module
==========

' works also without interface .. end interface, inner.. end inner
'
interface
  dim as int ptr abc
  declare function ptr bat(int x) as string
end interface


inner
  dim static pp as int
  int a : @abc=@a
  'static function f(int x) as string, link @bat
  static function f(int x) link @bat as string
  pp=x
  print "f4 " x

    return "ok"
  end function
  a=87654
end inner

==============
end module 'mm
==============
'
'test go
print abc   '
print bat(102040) 'ok

Title: Re: Static function Link example
Post by: Charles Pegge on February 01, 2025, 10:35:07 PM
inner .. end inner makes the encapsulation. You can test this by trying to print a from the outside. It is hidden.
Title: Re: Static function Link example inner.. end inner
Post by: Frank Brübach on February 02, 2025, 12:43:18 AM
Yes thanks does Work Here value stays invisible outside the inner.. end inner Block

' test 3 invisible value outside -- inner.. end inner
' go
==========
module
==========

' works also without interface .. end interface, inner.. end inner
' but for this case the value ax outside is invisible
'
interface
  dim as int ptr abc
  declare function ptr bat(int x) as string
end interface


inner
  dim static pp as int
  int ax : @abc=@ax
  'static function f(int x) as string, link @bat
  static function f(int x) link @bat as string
  pp=x
  print "f4 " x

    return "ok"
  end function
  ax=87654
end inner

print "ax outside" + ax ' no result -> invisible :-) good!

==============
end module 'mm
==============
'
'test go
print "abc " + abc   '
print bat(102040) 'ok
' ends