• Welcome to Theos PowerBasic Museum 2017.

zXref (version 1.10)

Started by Patrice Terrier, August 14, 2009, 08:25:54 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Paul Elliott

Theo,

Ok, thanks for pointing that out.

I was just trying to figure out how to handle the #Include Once & #Include This Once. For the latter,
I'm just going to leave in the code already read up to that point ( it gets messy having to undo
anything already input if that is not the first real line of code ).

I was just running all the PB or Jose WinAPI files into 1 main file to get a big list of equates and
check out if I was handling #IF...#ENDIF blocks correctly. And to check how to store equate values
for comparison or use in building other equates.

I guess it's time to track down my problem with multiple copies of the same file open at once.
Something to do this weekend.


Larry Charlton

Quote from: Theo Gottwald on April 06, 2012, 07:47:55 AM
...BUT, an Included file is technically same like MACRO.
You see that, if you intermix MACROS and Include files, they even share the same "NESTING DEPT".

The reason for including a file twice is the same, why you should use a MACRO twice.
Include files are not solely for using WinAPI, or reading definitions,
but you can also use them to include your personal code-stuff "as often as you want" without always typing it again.

Theo,

Thanks for that!  I read that and it percolated in the back of my mind for a bit.  Puts a whole new light on #include :)  I'm not sure I'll use it, but it occurs to me it could be used to include common methods (or interfaces) in several classes.  Going further with a bit of naming convention it could be used as a sort of templating.  Here's a simple example

Name_Create.inc
  vName = "Theo!"

Name_Definition.inc
    Property Get Name() As String
      Property = vName
    End Property
    Property Set Name( value As String )
      vName = value
    End Property


Name_Instance.inc
  Instance vName As String

Test.bas
#Compile Exe
#Dim All

Function PBMain () As Long
  Local v1 As i1
  Local v2 As i2

  v1 = Class "C1"
  ? v1.Name + ", " + v1.Phone

  v2 = Class "C2"
  ? v2.Name + ", " + Format$( v2.Age, "0" )
End Function


Class C1
  #Include "Name_Instance.inc"
  Instance vPhone As String

  Class Method Create()
    vPhone = "704-555-1212"
    #Include "Name_Create.inc"
  End Method

  Interface i1
    Inherit IUnknown

    #Include "Name_Definition.inc"
    Property Get Phone() As String
      Property = vPhone
    End Property
    Property Set Phone( value As String )
      vPhone = value
    End Property
  End Interface
End Class


Class C2
  #Include "Name_Instance.inc"
  Instance vAge As Long

  Class Method Create()
    vAge = 140
    #Include "Name_Create.inc"
  End Method

  Interface i2
    Inherit IUnknown

    #Include "Name_Definition.inc"
    Property Get Age() As Long
      Property = vAge
    End Property
    Property Set Age( value As Long )
      vAge = value
    End Property
  End Interface
End Class