Archive for the ‘Procedure’ Category

Procedure

Posted: 2017-01-21 in Procedure

Q:
Say I have a function that returns an array (or datetime, or whatever), if that function fails I want to return null and then check for that null (as you can/would in C#), something like the code below. What are the rules for this in lianja

Code:
function test(ok)
  if (ok)
    return array()
  else
    return null
  endif
endfunc

x = test(.F.)
if x=null
  //The function failed
endif

A:

Code:
function test(ok)
  if (ok)
    return array()
else
    return .null.
  endif
endfunc

x = test(.F.)
if isnull(x)
  //The function failed
endif

Q:
it looks like ‘tcPassedIn1’ is local to ‘Test1’ and not private:

Code:
proc page1_section2_field2_click()       
local lcTest
lcTest = "Original String"
        Test1(lcTest)
MessageBox(lcTest, 0)
endproc

proc Test1(tcPassedIn1)
tcPassedIn1 = "Var not overwritten"
Test2(tcPassedIn1)
MessageBox(tcPassedIn1, 0)
endproc

proc Test2(tcPassedIn2)
tcPassedIn2 = "Var overwritten"
endproc

A:
Parameters in the proc declaration are local as you point out.
This is not standard VFP, it’s another useful extension that reduces typing.
No need for lparameters… statement



Procedure

Posted: 2017-01-21 in Procedure

use create them in a procedure library and issue:
SET PROCEDURE TO yourlibraryname in the init or load event for the app.
You can subclass any of the lianja UI framework classes.
These classes can then be used in both custom sections and gadgets.


Q:
If I use the p_valid.prg as a standalone I must one as part of the script files in the app?
It would be available for the whole app?
How would it be to create it as a function inside the function library?
And finally, sorry for the abuse, if it is part of the page or section where the event would be used to validate input when it loses focus?
A:
If it is a standalone prg, just click the + button at the bottom of the ‘Files’ in the Sidebar in the Apps Workspace and it will prompt you for the filename. The default file extension is ‘.prg’.
Yes, it will be available for the whole App. When you Deploy, it will be deployed as a .dbo (pseudo-compiled) file.
If you have lots of functions you want to use, you can put them in a function/procedure library (create this using the + button as before):

Then use set procedure to <lib> additive in a delegate called before the function is required, for example in the app.load() or the app.ready() (or a delegate for the relevant Page or Section).

Or, as in the screenshot above, you can add functions (‘anotherfuncstill’ here) in with the event delegates.
The custom libraries for event delegates (created when you create your first delegate) are opened for you automatically; there is no need to use set procedure in this case.

Pages and Sections can also have a ‘Valid When‘ event delegate called after the field validation.