Address of a procedure included in UDT ? [solved]

General FreeBASIC programming questions.
Post Reply
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Address of a procedure included in UDT ? [solved]

Post by fxm »

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: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

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
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Post by fxm »

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: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

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

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

Post by fxm »

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.
Post Reply