John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 38
Текст из файла (страница 38)
Note that KEYC consumes the signal (unlikeIOCANCEL), so IOWAITSTAT should not be usedafter KEYC.OPL COMMAND LISTKILLMARK221Removes a bookmarkUsage: KILLMARK b%Removes the bookmark b%, which has previously beenreturned by BOOKMARK, from the current view ofa database.See BOOKMARK, GOTOMARK.KMODGets the state of the modifier keysUsage: k%=KMODReturns a code representing the state of the modifierkeys (whether they were pressed or not) at the time ofthe last keyboard access, such as a KEY function. Themodifiers have these codes:KKmodShift%KKmodControl%KKmodCaps%KKmodFn%241632Shift downCtrl downCaps lock onFn downThese constants are supplied in Const.oph.If there was no modifier, the function returns 0.
If acombination of modifiers was pressed, the sum of theircodes is returned – for example, 20 is returned if Ctrl(4) was held down and Caps lock (16) was on.Always use immediately after a KEY/KEY$/GET/GET$statement.The value returned by KMOD has one binary bitset for each modifier, as shown above. By using thelogical operator AND on the value returned by KMODyou can check which of the bits are set, in order to seewhich modifier keys were held down. For more detailson AND, see Operators and logical expressions.Example:PROC modifier:LOCAL k%,mod%PRINT "Press a key" :k%=GETCLS :mod%=KMODPRINT "Key code",k%,"with"IF mod%=0PRINT "no modifier"ENDIF222OPL COMMAND LISTIF mod% AND KModShift%PRINT "Shift down"ENDIFIF mod% AND KModControl%PRINT "Control down"ENDIFIF mod% AND KModCaps%PRINT "Caps Lock on"ENDIFIF mod% AND KModFn%PRINT "Fn down"ENDIFENDPLASTPositions to the last recordUsage: LASTPositions to the last record in a view.LCLOSECloses the device opened with LOPENUsage: LCLOSECloses the device opened with LOPEN.
The device isalso closed automatically when a program ends.LEFT$Gets the leftmost characters of a stringUsage: b$=LEFT$(a$,x%)Returns the leftmost x% characters from the string a$.For example, if n$ has the value Charles, thenb$=LEFT$(n$,3) assigns Cha to b$.LENLength of a stringUsage: a%=LEN(a$)Returns the number of characters in a$.E.g. if a$ has the value 34 Kopechnie Drive thenLEN(a$) returns 18.You might use this function to check that a data filestring field is not empty before displaying:IF LEN(A.client$)PRINT A.client$ENDIFOPL COMMAND LISTENALLOC223Gets the length of a previously allocated cellUsage: len&=LENALLOC(pcell&)Returns the length of the previously allocated cell atpcell&. An error will be raised if the cell addressargument is not in the range known by the heap.See also SETFLAGS if you require a 64K memory limitto be enforced. If the flag is set to restrict the limit, len&is guaranteed to fit into an integer.ARMCells are allocated lengths that are the smallest multipleof four greater than the size requested because theARM processor requires a 4-byte word alignment for itsmemory allocation.LNNatural logarithmUsage: a=LN(x)Returns the natural (base e) logarithm of x.Use LOG to return the base 10 log of a number.LOADMLoads a translated OPL moduleUsage: LOADM module$Loads a translated OPL module so that procedures inthat module can be called.
Until a module is loadedwith LOADM, calls to procedures in that module willgive an error.module$ is a string containing the name of themodule. Specify the full filename only where necessary.Example: LOADM "MODUL2"Up to 8 modules can be in memory at any one time,including the top-level module; if you try to LOADMa ninth module, you get an error.
Use UNLOADM toremove a module from memory so that you can load adifferent one.By default, LOADM always uses the folder of thetop-level module. It is not affected by the SETPATHcommand.LOCLocates a substring within a stringUsage: a%=LOC(a$,b$)224OPL COMMAND LISTReturns an integer showing the position in a$ where b$occurs, or zero if b$ doesn’t occur in a$. The searchmatches upper and lowercase.Example: LOC("STANDING","AND") would returnthe value 3 because the substring AND starts at thethird character of the string STANDING.LOCALDeclares procedure-local variablesUsage: LOCAL variablesUsed to declare variables that can be referenced onlyin the current procedure.
Other procedures may usethe same variable names to create new variables.Use GLOBAL to declare variables common to allcalled procedures.The variables may be of four types, depending onthe symbol they end with:Variable names not ending with $, %, &, or () arefloating point variables, for example price, xThose ending with a % are integer variables, forexample x%, sales92%Those ending with an & are long integer variables, forexample x&, sales92&Those ending with a $ are string variables.
String variable names must be followed by the maximum lengthof the string in brackets, for example names$(12),a$(3)Array variables have a number immediately followingthem in brackets, which specifies the number of elements in the array. Array variables may be of any type,for example: x(6),y%(5),f$(5,12),z&(3).When declaring string arrays, you must give twonumbers in the brackets.
The first declares the numberof elements, the second declares their maximum length.For example, surname$(5,8) declares five elements,each up to eight characters long.Variable names may be any combination of up to32 numbers, alphabetic letters, and the underscorecharacter. They must start with a letter or an underscore.The length includes the %, &, or $ sign, but not the () instring and array variables.More than one GLOBAL or LOCAL statement may beused, but they must be on separate lines, immediatelyafter the procedure name.OPL COMMAND LIST225See also GLOBAL, CONST.LOCKBlocks system requests to change files or quitUsage: LOCK ONorLOCK OFFMarks an application as locked or unlocked.
When anapp is locked with LOCK ON, the System screen willnot send it events to change files or quit.If, for example, you move to the task list or thedocument name in the System screen, try to stop thatrunning app by using the ‘Close file’ button or Ctrl+E,a message will appear, indicating that the app cannotclose down at that moment.You should use LOCK ON if your application usesa command, such as EDIT, MENU, or DIALOG, whichaccesses the keyboard.
You might also use it when theapp is about to go busy for a considerable length oftime, or at any other point where a clean exit is notpossible. Do not forget to use LOCK OFF as soon aspossible afterwards.An application is initially unlocked.LOGLogarithmUsage: a=LOG(x)Returns the base 10 logarithm of x.Use LN to find the base e (natural) log.LOPENOpens a device for printingUsage: LOPEN device$Opens the device to which LPRINTs are to be sent.No LPRINTs can be sent until a device has beenopened with LOPEN.You can open any of these devices:The serial port, with LOPEN "TTY:A"A file on the Symbian OS device. Any existing file ofthe name given will be overwritten when you print to itOnly one device may be open at any one time.
UseLCLOSE to close the device. LOPENned devices alsoclose automatically when a program finishes running.LOWER$Converts a string to lowercaseUsage: b$=LOWER$(a$)226OPL COMMAND LISTConverts any uppercase characters in the string a$ tolowercase and returns the completely lowercase string.E.g. if a$="CLARKE", LOWER$(a$) returns the string"clarke".Use UPPER$ to convert a string to uppercase.LPRINTPrints a list to the device opened using LOPENUsage: LPRINT list of expressionsPrints a list of items, in the same way as PRINT, exceptthat the data is sent to the device most recently openedwith LOPEN.The expressions may be quoted strings, variables, orthe evaluated results of expressions. The punctuation ofthe LPRINT statement (commas, semicolons, and newlines) determines the layout of the printed text, in thesame way as PRINT statements.If no device has been opened with LOPEN you willget an error.See PRINT for displaying to the screen.See LOPEN for opening a device for LPRINT.MAXMaximum valueUsage: m=MAX(list)orm=MAX(array(),element)Returns the greatest of a list of numeric items.
Thelist can be either:A list of variables, values, and expressions, separatedby commasorThe elements of a floating point array.When operating on an array, the first argument mustbe the array name followed by (). The second argument,separated from the first by a comma, is the number ofarray elements you wish to operate on.
For example,m=MAX(arr(),3) would return the value of the largest ofelements arr(1), arr(2), and arr(3).mCARDDefines a menu cardUsage: mCARD title$,n1$,k1%ormCARD title$,n1$,k1%,n2$,k2% etc.OPL COMMAND LIST227Defines a menu. When you have defined all of themenus, use MENU to display them.title$ is the name of the menu. From one to eightitems on the menu may be defined, each specified bytwo arguments.
The first is the item name, and thesecond the keycode for a shortcut key. This specifies akey which, when pressed together with Ctrl, will selectthe option. If the keycode is for an uppercase key, theshortcut key will be Shift+Ctrl.The options can be divided into logical groups bydisplaying a separating line under the final option in agroup. To do this, pass the negative value corresponding to the shortcut key keycode for the final option inthe group. For example, – %A specifies shortcut keyShift+Ctrl+A and displays a separating line under theassociated option in the menu.Menu items without shortcuts can be specified usingshortcut values between 1 and 32. For these items thevalue specified is still returned if the item is selected.Any item with a shortcut of zero will NOT be added tothe menu.Other properties can be specified by adding oneor more of the following flags to the shortcut keycode:KMenuDimmed%KMenuSymbolOn%$1000$2000KMenuSymbolIndeterminate%$4000KMenuCheckBox%KMenuOptionStart%$0800$0900KMenuOptionMiddle%$0A00KMenuOptionEnd%$0B00menu item is dimmedcheckbox option buttonsymbol oncheckbox or option buttonsymbol indeterminateitem has a checkboxitem starts an option buttonlistin the middle of an optionbutton listends an option button listThese constants are supplied in Const.oph.The start, middle, and end option buttons are forspecifying a group of related items that can be selectedexclusively (i.e.
if one item is selected then the othersare deselected). The number of middle option buttonsis variable. A single menu card can have more thanone set of option buttons and checkboxes, but optionbuttons in a set should be kept together. For speed,228OPL COMMAND LISTOPL does not check the consistency of these items’specification.If a separating line is required when any of theseeffects have been added, you must be sure to negatethe whole value, not just the shortcut key keycode.For example:mCARD "Options","View1",%A OR $2900,"View2",(%B OR $B00), "Another option",%CHere, the second shortcut key keycode and its flagvalue is correctly negated to display a separating line.A ‘Too wide’ error is raised if the menu title lengthis greater than or equal to 40.