Friday, December 14, 2012

How to hide codes in your class?


ssClasses has gone from an open source library to per subscription with hidden codes and back to open source library.  And it cannot be helped that some are wondering how I was able to hide the codes before, and so a question raised inside Foxite.

And so I believe it is better for me to explain here the process involved in hiding the codes.

How was I able to do that?

Since I am using ssClasses library on my end in actual production of my ERP app, the codes are always visible on my end.  For my subscribers then, I keep a separate folder named ss_sample - subscribers; where a small project is made just like what you see now in ssDemos.zip with all the forms to show how to use each class and a copy of the library is there. And by intention, I have hidden the codes to them because I do not want them to touch it and then come back to me complaining 'Jun I have a problem, your class is giving me error!' where it will be hard for me to trace what has happened especially if it is because they touched my codes and forgot to tell me so.  To avoid that problem, they cannot touch my codes by making it invisible to them.  Any thing they need or wanted before, they suggest to me and I do any enhancement on my end, then email them back with new updates.  That also works good for every one because the updates are not limited to that single user, new features will also be made available to others.

So how did I hide the codes?



In reality I am not hiding those. I am removing those.

How does the class works then if codes are removed?

For the hiding/removing process to be successful, you have to first compile the project.  The compilation process then generates an entry inside the library's ObjCode field which is of machine readable codes similar to when we compile a prg, it generates a separate .fxp file.  With class libraries, the codes are created inside that ObjCode field.  And those are used by our app if the codes in the Methods field are not there.

So this:



Will become this:



After the corresponding object codes are there, then all we need to do is remove all the codes in the Methods field:

CLOSE DATABASES ALL
USE myLibrary.vcx EXCLUSIVE
REPLACE Methods with '' ALL
PACK
CLOSE DATABASES ALL

Very Important!!!!  This process is irreversible!  That is why I am copying the library from my actual production usage to the sample for subscribers and I am doing those things on their copy and not on mine.  Before doing the above, make sure that you back up your existing library.

And that is it!  I have not hidden the codes, I removed those.  And the library remains usable because of the entries in ObjCodes.

Gotcha!

You should not put any codes inside the library anymore after you have done the above.  Because doing so will render your library (as well as the class inside it) useless because once you recompile your app and VFP saw any entry in the Methods field of the library, it will also update your library and remove what has been inside the ObjCode field and replace it with new ones.  Of course, that won't include your old codes.

Final Words!  Do these things carefully at your own risk!



1 comment:

  1. Wow, a simple trick and not everyone know, thanks for the technique. Science is very useful

    ReplyDelete