Want to make class variables automatically available to all your databases? I think I found the secret.
I've found very little help on implementing Classes, but through quite a bit of trial and error I found out how to make a global/system class always available to all my databases. (And if you don't use classes, you're missing some HUGE benefits!)
I found three secrets to making this work, and I'm still crossing my fingers:
1) The help on Classes for v10 states "The last line of code that you paste must be 'end class'." That is absolutely correct, but you must add a carriage return after the 'end class' statement (I'm using 10.5 3432-3608, 64-bit Vista Home Premium). It would not work reliably for me without the carriage return.
I could actually test the class with any extra code inserted after 'end class' -- every time I 'Save' the code it executes -- but when it was debugged and working, I had to comment out or delete all the other code and make sure 'end class' was the very last line of the file, terminated with a carriage return. Only then, and after compiling to an .AEX file and copying it into my addin directory, would it work.
2) The help says to make the class 'global', but if you want it available to all your databases every time you must declare it 'system' instead.
3) To use the class, you must first 'dim' an instance of that class with a simple 'dim' statement of any variable for that class - your code will fail if the first time your code uses the class is via a static method. Use 'dim myClassVar as MyClass' in your code, for example, prior to using 'dim myClassVar as p = MyClass.CreateNewMyClass()', otherwise you'll get a type-unknown error.
If a couple of you could please confirm that this works, I'll add this into the code archive.
Here's a sample class (to keep things simple and clean, create a new empty database and then create a new class with the class editor):
Make sure that 'end class' is followed with a single carriage return. And make sure the class is defined as 'system' rather than 'global', otherwise it will be available only to the database where it is defined.
Then, follow the instructions to make an addin:
http://wiki.alphasoftware.com/Compil...pile%20scripts
http://wiki.alphasoftware.com/Managi...ghlight=addins
Also check this:
http://wiki.alphasoftware.com/Classe...+in+Version+10
Close and restart AlphaFive (with further testing on my system, I don't need to do this).
Then open any database where you want to use this class variable (or any other you've created that you want to be available always just like all other variable types). To use the class, your code path must encounter a simple dim statement first before the static method will work.
To test this, enter:
I hope this works for you - it's making my programming a lot better with a lot less typing and hassle!
I've found very little help on implementing Classes, but through quite a bit of trial and error I found out how to make a global/system class always available to all my databases. (And if you don't use classes, you're missing some HUGE benefits!)
I found three secrets to making this work, and I'm still crossing my fingers:
1) The help on Classes for v10 states "The last line of code that you paste must be 'end class'." That is absolutely correct, but you must add a carriage return after the 'end class' statement (I'm using 10.5 3432-3608, 64-bit Vista Home Premium). It would not work reliably for me without the carriage return.
I could actually test the class with any extra code inserted after 'end class' -- every time I 'Save' the code it executes -- but when it was debugged and working, I had to comment out or delete all the other code and make sure 'end class' was the very last line of the file, terminated with a carriage return. Only then, and after compiling to an .AEX file and copying it into my addin directory, would it work.
2) The help says to make the class 'global', but if you want it available to all your databases every time you must declare it 'system' instead.
3) To use the class, you must first 'dim' an instance of that class with a simple 'dim' statement of any variable for that class - your code will fail if the first time your code uses the class is via a static method. Use 'dim myClassVar as MyClass' in your code, for example, prior to using 'dim myClassVar as p = MyClass.CreateNewMyClass()', otherwise you'll get a type-unknown error.
If a couple of you could please confirm that this works, I'll add this into the code archive.
Here's a sample class (to keep things simple and clean, create a new empty database and then create a new class with the class editor):
Code:
define class system Person dim lastname as c = "Smith" dim firstname as c function [static] NewPerson as p (Last as c, First as c) dim NewVar as Person NewVar.lastname = Last NewVar.firstname = First NewPerson = NewVar end function end class
Then, follow the instructions to make an addin:
http://wiki.alphasoftware.com/Compil...pile%20scripts
http://wiki.alphasoftware.com/Managi...ghlight=addins
Also check this:
http://wiki.alphasoftware.com/Classe...+in+Version+10
Close and restart AlphaFive (with further testing on my system, I don't need to do this).
Then open any database where you want to use this class variable (or any other you've created that you want to be available always just like all other variable types). To use the class, your code path must encounter a simple dim statement first before the static method will work.
To test this, enter:
Code:
dim test as Person 'you must do this first - if you comment this out, the next line will fail dim myFriend as p = Person.NewPerson("Jones","Bob")
Comment