NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Keith on May 05, 2014, 11:30:56 PM

Title: Code re-use
Post by: Keith on May 05, 2014, 11:30:56 PM
I have about 400 lines of code in a set of routines which originally were executed within one procedure.  I am now finding that I need to execute this from other procedures and don't want to just replicate the code because it would then require updating twice (or thrice etc).

Can I create a shared code file (a DLL?) that I can call from wherever as a shared procedure.  Could someone point me to where I could learn how to do this or is there another way?

Thanks

Keith
Title: Re: Code re-use
Post by: terryd on May 05, 2014, 11:40:28 PM
Keith.
You could create a source file that does the same and then call it with parameters from wherever you want it as long as you only need a max of 1 response. You can add (NetWebServerWorker p_web)  to your prototype and then access session variables from within the source file.
Title: Re: Code re-use
Post by: Keith on May 06, 2014, 01:56:02 AM
Hi Terry

Thanks for this. 

>> as long as you only need a max of 1 response.

Not sure what you mean by this.  The current procedure generates many new values for session variables and creates keyed records in a memory table.  Would this be ok?

If I create a new NetWebSource procedure and add my code to it via an embed (Processed Code) and I call it then the 'parameters' are the current session variables so as long as they are available from within the procedure via p_web.gsv that should be ok?

I presume that the new procedure will be thread safe?

Of course, I can try it.

Keith
Title: Re: Code re-use
Post by: Bruce on May 06, 2014, 03:40:56 AM
Hi Keith,

>> >>  as long as you only need a max of 1 response.

>> Not sure what you mean by this. 

Procedures in clarion can only return a single value (ie a single returned value as it completes.)

>> The current procedure generates many new values for session variables and creates keyed records in a memory table.  >> Would this be ok?

yes.

>> If I create a new NetWebSource procedure and add my code to it via an embed (Processed Code) and I call it then the 'parameters' are the current session variables so as long as they are available from within the procedure via p_web.gsv that should be ok?

yes, as long as your procedure has the prototype/parameters set to
(NetWebServerWorker p_web)

>> I presume that the new procedure will be thread safe?

as long as you don't use any global, unThreaded variables, yes, it will be ThreadSafe.

cheers
Bruce
Title: Re: Code re-use
Post by: terryd on May 06, 2014, 05:10:54 AM
Hi Keith
Note I'm talking about a bog standard Clarion source procedure. You don't need to create a netwebSource procedure unless you need to display something on the browser as you process. If you are just setting some session variables, calling the source procedure doing something inside using those values then returning, a source procedure should be fine.
Title: Re: Code re-use
Post by: Keith on May 06, 2014, 07:01:03 PM
Thanks for the help.

I have created a new NetWebSource procedure - CalculateResults with Prototype and parameters set to (NetWebServerWorker p_web).

In my code I try to execute it via; CalculateResults() and get a compile error 'No matching prototype available'

What do I need to add here?

Thanks

Keith
Title: Re: Code re-use
Post by: Rene Simons on May 06, 2014, 07:48:45 PM
Hi,

You should use: calculateResults(p_web).
p_web is the object which has all your netwebserverworker properties and methods.
You have defined the prototype NetwebServerWorker in the procedure. So that is what the compiler expects for it. 
After the call, you will find the resultvalues in the session values you set in the procedure.

René Simons
Title: Re: Code re-use
Post by: Keith on May 11, 2014, 04:30:56 PM
Hi all responders

Thanks for the help - this all now works well.  A new window of understanding has opened and the view is great.

Cheers

Keith