NetTalk Central

Author Topic: Code re-use  (Read 4567 times)

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Code re-use
« 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
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Code re-use
« Reply #1 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.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Code re-use
« Reply #2 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
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Code re-use
« Reply #3 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

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Code re-use
« Reply #4 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.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Code re-use
« Reply #5 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
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Code re-use
« Reply #6 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
« Last Edit: May 07, 2014, 03:24:19 AM by Rene Simons »
Rene Simons
NT14.14

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Code re-use
« Reply #7 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
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27