John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 27
Текст из файла (страница 27)
Thisshould not be done too often since it uses considerableprocessor power.Compaction can also be done automatically on closing a file by setting the appropriate flag using SETFLAGS.146CONTINUEOPL COMMAND LISTJump to loop test conditionUsage: CONTINUEMakes a program immediately go to the UNTIL...line of a DO...UNTIL loop or the WHILE... line ofa WHILE...ENDWH loop, i.e.
to the test condition. Inthis example the CONTINUE will take you back to theWHILE statement:WHILE a<b...IF a=cCONTINUEENDIF...ENDWH...See also BREAK.CONSTDeclares a constantUsage: CONST KConstantName=constantValueDeclares constants that are treated as literals, notstored as data.
The declarations must be made outside any procedure, usually at the beginning of themodule. KConstantName has the normal type specification indicators (%, &, $, or nothing for floating pointnumbers). CONST values have global scope, and arenot overridden by LOCAL or GLOBAL variables withthe same name: in fact the translator will not allowthe declaration new variables with a duplicate name.By convention, all constants should be named with aleading K to distinguish them from variables.It should be noted that it is not possible to defineconstants with values smaller than −32768 (for integers) and −214748648 (for long integers) in decimals,but hexadecimal notation may be used instead (i.e.values of $8000 and &80000000, respectively).COPYCopies filesUsage: COPY src$,dest$Copies the file src$, which may be of any type, tothe file dest$.
Any existing file with the name dest$ isOPL COMMAND LIST147deleted. You can copy across devices. You can alsouse wildcards if you wish to copy more than one file ata time.If src$ contains wildcards, dest$ may specify eithera filename similarly containing wildcards or just thedevice and directory to which the files are to be copiedunder their original names.Example (to copy all the files from internal memory(in \opl) to d:\me\):COPY "c:\opl\*","d:\me\"(Remember the final backslash on the directory name.)COSCosineUsage: c=COS(x)Returns the cosine of x, where x is an angle in radians.To convert from degrees to radians, use the RADfunction.COUNTCounts records in the current data fileUsage: c%=COUNTReturns the number of records in the current data file.This number will be 0 if the file is empty.If you try to count the number of records in aview while updating the view an ‘Incompatible updatemode’ error will be raised (this will occur betweenassignment and APPEND/UPDATE or between MODIFY/INSERT and PUT).CREATECreates a table in a databaseUsage: CREATE tableSpec$,log,f1,f2,...Creates a table in a database.
The database is alsocreated if necessary. Immediately after calling CREATE, the file and view (or table) is open and readyfor access.tableSpec$ contains the database filename andoptionally a table name and the field names to becreated within that table.
For example:CREATE "clients FIELDS name(40), tel TO phone", D,n$, t$148OPL COMMAND LISTThe filename is clients. The table to be created withinthe file is phone. The comma-separated list, betweenthe keywords FIELDS and TO, specifies the field nameswhose types are specified by the field handles (i.e.n$, t$).The name field has a length of 40 bytes, asspecified within the brackets that follow it. Thetel field has the default length of 255 bytes. Thismechanism is necessary for creating some indexes.See dBase.opx – Database handling for more details onindex creation.The filename may be a full file specification of up to255 characters.
A field name may be up to a maximumof 64 characters long. Text fields have a default lengthof 255 bytes.log specifies the logical filename A to Z. This is usedas an abbreviation for the filename when you use otherdata file commands such as USE.CURSORSets the text cursorUsage: any ofCURSOR ONCURSOR OFFCURSOR id%CURSOR id%,asc%,w%,h%CURSOR id%,asc%,w%,h%,type%CURSOR ON switches the text cursor on at the currentcursor position. Initially, no cursor is displayed.You can switch on a graphics cursor in a windowby following CURSOR with the ID of the window. Thisreplaces any text cursor. At the same time, you can alsospecify the cursor’s shape, and its position relative tothe baseline of text.asc% is the ascent – the number of pixels (−128 to127) by which the top of the cursor should be abovethe baseline of the current font.
h% and w% (both from0 to 255) are the cursor’s height and width.If you do not specify them, the following defaultvalues are used:asc%h%w%current font’s ascentcurrent font’s heightKCursorTypeNotFlashing%OPL COMMAND LIST149If type% is given, it can have these effects:KCursorTypeNotFlashing%KCursorTypeGrey%24not flashinggreyThese constants are supplied in Const.oph.You can add these values together to combineeffects – if type% is 6 a grey non-flashing cursor isdrawn. Using 1 for type% just displays a default graphics cursor, as though no type had been specified.An error is raised if id% specifies a bitmap ratherthan a window.CURSOR OFF switches off any cursor.DATETOSECSGets the number of seconds since 1/1/1970Usage: s&=DATETOSECS(yr%,mo%,dy%,hr%,mn%,sc%)Returns the number of seconds since 00:00 on 1/1/1970at the date/time specified.Raises an error for dates before 1/1/1970.The value returned is an unsigned long integer.(Values up to +2147483647, which is 03:14:07 on19/1/2038, are returned as expected.
Those from+2147483648 upwards are returned as negativenumbers, starting from −2147483648 and increasingtowards zero.)See also SECSTODATE, HOUR, MINUTE, SECOND.DATIM$Current date and timeUsage: d$=DATIM$Returns the current date and time from the system clockas a string – for example: "Fri 16 Oct 1992 16:25:30".The string returned always has this format – 3 mixedcase characters for the day, then a space, then 2 digitsfor the day of the month, and so on.The string returned by DATIM$ can be parsed withMID$ using the following values for offsets withinthe string:150OPL COMMAND LISTKDatimOffDayName%KDatimOffDay%KDatimOffMonth%KDatimOffYear%KDatimOffHour%KDatimOffMinute%KDatimOffSecond%15812172023offset of the day name (Fri)offset of the day of the month (16)offset of the month name (Oct)offset of the year number (1992)offset of the hour (16)offset of the minute (25)offset of the second (30)These constants are supplied in Const.oph.Date.opx provides a large set of procedures formanipulating dates and for accurate timing.DAYCurrent day of the monthUsage: d%=DAYReturns the current day of the month (1 to 31) from thesystem clock.DAYNAME$Converts a number to a day nameUsage: d$=DAYNAME$(x%)Converts x%, a number from 1 to 7, to the dayof the week, expressed as a three-letter string.
E.g.d$=DAYNAME$(1) returns MON.Example:PROC Birthday:LOCAL d&,m&,y&,dWk%DOdINITdTEXT "","Date of birth",2dTEXT "","eg 23 12 1963",$202dLONG d&,"Day",1,31dLONG m&,"Month",1,12dLONG y&,"Year",1900,2155IF DIALOG=0 :BREAK :ENDIFdWk%=DOW(d&,m&,y&)CLS :PRINT DAYNAME$(dWk%),PRINT d&,m&,y&dINIT dTEXT "","Again?",$202dBUTTONS "No",%N,"Yes",%YUNTIL DIALOG<>%yENDPSee also DOW.OPL COMMAND LISTDAYS151Gets the number of days since 1/1/1900Usage: d&=DAYS(day%,month%,year%)Returns the number of days since 1/1/1900.Use this to find out the number of days betweentwo dates.Example:PROC deadline:LOCAL a%,b%,c%,deadlin&LOCAL today&,togo%PRINT "What day? (1-31)"INPUT a%PRINT "What month? (1-12)"INPUT b%PRINT "What year? (19??)"INPUT c%deadlin&=DAYS(a%,b%,1900+c%)today&=DAYS(DAY,MONTH,YEAR)togo%=deadlin&-today&PRINT togo%,"days to go"GETENDPSee also dDATE, SECSTODATE.Date.opx provides a large set of procedures formanipulating dates and for accurate timing.DAYSTODATEConverts the number of days since 1/1/1900 to a dateUsage: DAYSTODATE days&,year%,month%,day%This converts days&, the number of days since 1/1/1900,to the corresponding date, returning the day of the monthto day%, the month to month% and the year to year%.This is useful for converting the value set by dDATE,which also gives days since 1/1/1900.dBUTTONSDefines exit keysUsage: dBUTTONS p1$,k1%, p2$,k2%, p3$,k3%,...Defines exit keys to go at the bottom or side of a dialog.One or more exit keys can be defined with a p$,k%pair.
Each pair specifies an exit key; p$ is the text to bedisplayed on it, while k% is the keycode of the shortcut152OPL COMMAND LISTkey. DIALOG returns the keycode of the key pressed(in lowercase for letters).For alphabetic keys, use the % sign – %A means‘the code of A’, and so on. The shortcut key is thenCtrl+alphabetic key. Character codes lists the codesfor keys (such as Tab) that are not part of the characterset.