John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 40
Текст из файла (страница 40)
The string will be up to y% characters wide.If y% is negative then the string is right-justified,for example NUM$(1.9,−3) returns "2" where there aretwo spaces to the left of the 2.If y% is positive no spaces are added: e.g.NUM$(−3.7,3) returns "–4".If the string returned to n$ will not fit in the widthy%, then the string will just be asterisks; for exampleNUM$(256.99,2) returns "**".See also FIX$, GEN$, SCI$.ONERREstablishes an error handlerUsage:ONERR label::...ONERR OFFor just:ONERR label...ONERR OFF236OPL COMMAND LISTONERR label:: establishes an error handler in a procedure.
When an error is raised, the program jumps tothe label:: instead of the program stopping and an errormessage being displayed.The label may be up to 32 characters long startingwith a letter or an underscore. It ends with a doublecolon (::), although you don’t need to use this in theONERR statement.ONERR OFF disables the ONERR command, so thatany errors occurring after the ONERR OFF statementno longer jump to the label.It is advisable to use the command ONERR OFFimmediately after the label:: which starts the errorhandling code.OPENOpens an existing table in a databaseUsage: OPEN query$,log,f1,f2, ...Opens an existing table (or a ‘view’ of a table) from anexisting database, giving it the logical view name logand handles for the fields f1, f2. log can be any letterin the range A to Z.query$ specifies the database file, the required tableand fields to be selected.For example:OPEN "clients SELECT name, tel FROMphone",D,n$,t$The database name here is clients and the table name isphone.
The field names are enclosed by the keywordsSELECT and FROM and their types should correspondwith the list of handles (i.e. n$ indicates that the namefield is a string).Replacing the list of field names with * selects all thefields from the table.query$ is also used to specify an ordered viewand if a suitable index has been created, then it willbe used.OPEN "people SELECT name,number FROMphoneBook ORDER BY nameASC, number DESC",G,n$,num%OPL COMMAND LIST237would open a view with name fields in ascendingalphabetical order and if any names were the samethen the number field would be used to order theserecords in descending numerical order.If the specification of the database includes embedded spaces, for example in the name of the folder, thename must be enclosed in quotes, so for example thefollowing correctly fails:OPEN "c:\folder with spaces\file withspaces",a,name$whereas the following works:OPEN """c:\folder with spaces\file withspaces""",a,name$See also CREATE, USE, OPENR.OPENROpens a table as read-only in an existing databaseUsage: OPEN query$,log,f1,f2, ...This command works exactly like OPEN except that theopened file is read-only.
In other words, you cannotAPPEND, UPDATE, or PUT the records it contains.This means that you can run two separate programsat the same time, both sharing the same file.PARSE$Parses a filenameUsage: p$=PARSE$(f$,rel$,var off%())Returns a full file specification from the filename f$,filling in any missing information from rel$.The offsets to the filename components in the returnedstring is returned in off%(), which must be declared withat least 6 integers.
Index values for off%() are:KParseAOffFSys%KParseAOffDev%KParseAOffPath%KParseAOffFilename%KParseAOffExt%KParseAOffWild%123456filing system name offsetdevice name offsetpath offsetfilename offsetfile extension offsetflags for wildcards inreturned string. See below238OPL COMMAND LISTThe flag values in offset%(KParseAOffWild%) are:KParseWildNone%KParseWildFilename$KParseWildExt$KParseWildBoth$0123no wildcardswildcard in filenamewildcard in file extensionwildcard in bothThese constants are supplied in Const.oph.If rel$ is not itself a complete file specification, thecurrent filing system, device, and/or path are used asnecessary to fill in the missing parts.f$ and rel$ should be separate strings.p$=PARSE$("NEW","C:\Documents\*.MBM",x%())sets p$ to C:\Documents\NEW.MBM and x%() to(1,1,3,14,17,0).PAUSEWaits for a length of timeUsage: PAUSE x%Pauses the program for a certain time, depending onthe value of x%:0+ve-vewaits for a key to be pressedpauses for x% twentieths of a secondpauses for x% twentieths of a second oruntil a key is pressedSo PAUSE 100 would make the program pause for100/20 = 5 seconds, and PAUSE −100 would make theprogram pause for 5 seconds or until a key is pressed.If x% is less than or equal to 0, a GET, GET$, KEY,or KEY$ will return the key press that terminated thepause.
If you are not interested in this key press, but inthe one that follows it, clear the buffer after the PAUSEwith a single KEY function: PAUSE −10 :KEYYou should be especially careful about this if x%is negative, since then you cannot tell whether thepause was terminated by a key press or by the timerunning out.PAUSE should not be used in conjunction withGETEVENT or GETEVENT32 because events are discarded by PAUSE.OPL COMMAND LISTPEEKB239Reads a short integer from a byte of memoryp%=PEEKB(x&)The PEEK functions find the values stored in specificbytes. PEEKB returns the integer value of the byte ataddress x&.PEEKWReads an integer from memoryp%=PEEKW(x&)Returns the integer at address x&.PEEKLReads a long integer from memoryp&=PEEKL(x&)Returns the long integer value at address x&.PEEKFReads a floating point value from memoryp=PEEKF(x&)Returns the floating point value at address x&.PEEK$Reads a string from memoryp$=PEEK$(x&)Returns the string at address x&.PIReturns the value of PIUsage: p=PIReturns the value of (3.14...).POINTERFILTER Sets the pointer event maskUsage: POINTERFILTER filter%,mask%Filters pointer events in the current window out orback in.
Add the following flags together to achieve the240OPL COMMAND LISTdesired filter% and mask%:KPointerFilterEnterExit%KPointerFilterMove%KPointerFilterDrag%$0$1$2$4noneenter/exitmovedragThese constants are supplied in Const.oph.The bits set in filter% specify the settings to be used,1 to filter out the event and 0 to remove the filter. Onlythose bits set in mask% will be used for filtering. Thisallows the current setting of a particular bit to be leftunchanged if that bit is zero in the mask (i.e. mask%dictates what to change and filter% specifies the settingto which it should be changed).
For example:mask% = KPointerFilterEnterExit% +KPointerFilterDrag%REM allows enter/exit and drag settings to bechangedPOINTERFILTER KPointerFilterEnterExit%, mask%REM filters out enter/exit, but not dragging...POINTERFILTER KPointerFilterDrag%, mask%REM filters out drag and reinstates enter/exitInitially the events are not filtered out.See also GETEVENT32, GETEVENTA32.POKEBStores a short integer in a byte of memoryPOKEB x&,y%The POKE commands store values in specific bytes.POKEB stores the integer value y% (less than 256) inthe single byte at address x&.POKEWStores an integer in memoryPOKEW x&,y%Stores the integer y% across two consecutive bytes,with the least significant byte in the lower address, thatis x&.POKELStores a long integer in memoryOPL COMMAND LIST241POKEL x&,y&Stores the long integer y& in bytes starting at addressx&.POKEFStores a floating point value in memoryPOKEF x&,yStores the floating point value y in bytes starting ataddress x&.POKE$Stores a string in memoryPOKE$ x&,y$Stores the string y$ in bytes starting at address x&.Use ADDR to find out the address of your declaredvariables.POSGets the position in the current viewUsage: p%=POSReturns the number of the current record in the currentview.
POS (and POSITION) exist mainly for compatibility with older versions of OPL and you are advisedto use bookmarks instead.A file has no limit on the number of records. However, integers can only be in the range −32768 to+32767. Record numbers above 32767 are thereforereturned like this:record value32767327683276932770...65534returned by POS32767327683276732766...2To display record numbers, you can use this check:IF POS<0PRINT 65536+POSELSE242OPL COMMAND LISTPRINT POSENDIFNote: The number of the current record may be greaterthan or equal to 65535, and hence values may needto be truncated to fit into p%, giving inaccurate results.You are particularly advised to use bookmarks whendealing with a large number of records. Note, however,that the value returned by POS can become inaccurateif used in conjunction with bookmarks and multipleviews on a table.