StringTheory in a Class procedure

In my hand-coded project I want to use StringTheory in a procedure of one of my Classes. How do I set this up? str StringTheory placed within the procedure is not recognized: “Illegal data type: StringTheory.” Passing the string as a parameter also failed to work.

INCLUDE(‘StringTheory.inc’),ONCE

Class property
MyString &StringTheory

.Construct
Self.MyString &= NEW StringTheory

.Destruct
DISPOSE(Self.MyString)

as Kevin said, you will need an INCLUDE('StringTheory.inc'),ONCE
But let’s talk about WHERE you want the include.

If you have a property in the class, like Kevin showed
Then you’ll want to put the include in the .INC file of your class

If you’re just using a StringTheory object as data inside of a method
then you can put the include in the .CLW (but it will also work when the include is in the .INC) as the .INC is INCLUDE()d in in the .CLW

To my knowledge this is NOT DOCUMENTED:
→ It is important when you are INCLUD()'ing a class that has a module attribute that the INLCUDE itself appears OUTSIDE of any procedure.
That is to say the INLCUDE needs to be at the Global Scope or a Module scope.
Otherwise, while your program will compile, it will CRASH at runtime the first time you “touch” an instance of the class.

2 Likes

Thanks, each of you has been a very big help. I probably should have thought of and tried to place the Include within the Class.

If this is a hand-coded projects (ie. no APP files), then you will need to set the link and DLL mode on the project.
StringTheoryLinkMode => 1
StringTheoryDLLMode => 0

1 Like

And also the ABClinkMode and ABCDllMode. See stringtheory docs for details.

The below GitHub repo has 5 hand coded projects that use ST including the simplest Scratch Theory. There’s also a small class Bing Bang that lets you see inside ST, so includes it.

As you’ve been told you must get your Project Defines right; otherwise, it will compile but crash when run.

3 Likes