Address of a procedure included in UDT ? [solved]

General FreeBASIC programming questions.
fxm
Posts: 9179
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Address of a procedure included in UDT ? [solved]

Postby fxm » Jan 08, 2010 22:37

Can I get the the address of a Sub or Function procedure included in a "Type ... End Type" block ?

Example of program with compilation failed on the line 15 :
error 18: Syntax error in 'SubX = @THIS.Subroutine'

Code: Select all

DIM SHARED SubX AS SUB ()

TYPE Test
  Value AS INTEGER
  DECLARE SUB InitSubX ()
  DECLARE SUB Subroutine ()
END TYPE

SUB Test.Subroutine ()
  ' ...
  ' ...
END SUB

SUB Test.InitSubX ()
  SubX = @THIS.Subroutine
END SUB

If I replace the line 15 by : 'SubX = ProcPtr(THIS.Subroutine), I obtain one another error :
error 8: Undefined symbol, found 'THIS' in 'SubX = ProcPtr(THIS.Subroutine)'
Last edited by fxm on Apr 16, 2011 22:04, edited 2 times in total.
D.J.Peters
Posts: 7825
Joined: May 28, 2005 3:28

Postby D.J.Peters » Jan 08, 2010 23:52

Code: Select all

Dim Shared SubX As Sub ()

Type Test
  Value As Integer
  Declare Sub InitSubX ()
  declare static Sub Subroutine ()
End Type

Sub Test.Subroutine ()
  ' ...
  ' ...
End Sub

Sub Test.InitSubX ()
  SubX = @Subroutine
End Sub
fxm
Posts: 9179
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Jan 09, 2010 14:09

D.J.Peters,

Thank you very much for the quick response.

I have another similar question:
Is there also a way to define static data within an 'Type ... End Type' block?
D.J.Peters
Posts: 7825
Joined: May 28, 2005 3:28

Postby D.J.Peters » Jan 09, 2010 16:43

You know about FreeBASIC Wiki ;-)
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgType
read it and have fun

Joshy
fxm
Posts: 9179
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Jan 09, 2010 17:25

Yes, I already read this documentation carefully (and many other pages!).

I found a way a bit twisted (and complicated) to manage static data within a 'Type ... End Type' block:
I use a static function that contains the static data (Static As ...).
With a control input parameter, this function allows to initialize and / or read the static data.
This static data is then fully accessible.

Return to “General”

Who is online

Users browsing this forum: fxm, Majestic-12 [Bot] and 15 guests