John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 42
Текст из файла (страница 42)
Subsequently, any keyword thatchanges the size of the text screen font, such as FONTor SCREEN, will change some of these values andSCREENINFO should therefore be called again.See also FONT, SCREEN.SECONDGets the current time in secondsUsage: s%=SECONDReturns the current time in seconds from the systemclock (0 to 59).E.g.
at 6:00:33 SECOND returns 33.SECSTODATEConverts seconds to dateUsage: SECSTODATE s&,var yr%,var mo%,var dy%,varhr%,var mn%, var sc%,var yrday%Sets the variables passed by reference to the date corresponding to s&, the number of seconds since 00:00 on1/1/1970. yrday% is set to the day in the year (1–366).s& is an unsigned long integer. To use valuesgreater than +2147483647, subtract 4294967296 fromthe value.See also DATETOSECS, HOUR, MINUTE, SECOND,dDATE, DAYS.SETDOCSets a file to be a documentUsage: SETDOC file$Sets the file file$ to be a document.
This commandshould be called immediately before the creation offile$ if it is to be recognized as a document. SETDOCmay be used with the commands CREATE, gSAVEBIT,and IOOPEN.The string passed to SETDOC must be identical tothe name passed to the following CREATE or gSAVEBITotherwise a non-document file will be created. Exampleof document creation:250OPL COMMAND LISTSETDOC "myfile"CREATE "myfile",a,a$,b$SETDOC should also be called after successfully opening a document to allow the System screen to displaythe correct document name in its task list.In case of failure in creating or opening the requiredfile, you should take the following action:Creating – try to re-open the last file and if thisfails display an appropriate error dialog and exit.
Onreopening, call SETDOC back to the original file so theTask list is correct.Opening – as for creating, but calling SETDOC againis not strictly required.Database documents, created using CREATE, andmulti-bitmap documents, created using gSAVEBIT, willautomatically contain your application UID in the fileheader. For binary and text file documents createdusing IOOPEN and LOPEN, it is the programmer’sresponsibility to save the appropriate header in thefile. This is a fairly straightforward process and thefollowing suggests one way of finding out what theheader should be:Create a database or bitmap document in a test runof your application using SETDOC as shown above.Use a hex editor or hex dump program to find thefirst 16 bytes, or run the program below which readsthe four long integer UIDs from the test document.Write these four long integers to the start of the fileyou create using IOOPEN.INCLUDE "Const.oph"DECLARE EXTERNALEXTERNAL readUids:(file$)PROC main:LOCAL f$(255)WHILE 1dINIT "Show UIDs in document header"dPOSITION 1,0dFILE f$,"Document,Folder,Drive",0IF DIALOG=0RETURNENDIFOPL COMMAND LIST251readUids:(f$)ENDWHENDPPROC readUids:(f$)LOCAL ret%,h%LOCAL uid&(4),i%ret%=IOOPEN(h%,f$,KIoOpenModeOpen% ORKIoOpenFormatBinary%)IF ret%>=0ret%=IOREAD(h%,ADDR(uid&()),16)PRINT "Reading ";f$IF ret%=16WHILE i%<4i%=i%+1PRINT " Uid"+num$(i%,1)+"=",hex$(uid&(i%))ENDWHELSEPRINT " Error reading: ";IF ret%<0PRINT err$(ret%)ELSEPRINT "Read ";ret%;" bytes only ";PRINT "(4 long integers required)"ENDIFENDIFIOCLOSE(h%)ELSEPRINT "Error opening: ";ERR$(ret%)ENDIFENDPCreating text file documents using IOOPEN or LOPENhas two special requirements:You will need to save the required header as the firsttext record.
This will insert the standard text file linedelimiters CR LF (hex 0D 0A) at the end of the record.The specific 16 bytes required for your applicationmay itself however contain CR LF. Since you shouldknow when this is the case, you will need to readrecords until you have reached byte 16 in the document. This is clearly not a desirable state of affairs, butis inescapable given that text files were not designedto have headers. It is recommended that you request anew UID for your application if it contains CR LF.252OPL COMMAND LISTSee also GETDOC$.SETFLAGSSets an application’s flagsUsage: SETFLAGS flags&Sets flags to produce various effects when runningprograms. Use CLEARFLAGS to clear any flags thathave been set.
flags& is formed by adding one or moreof the following values:KRestrictTo64K&1restricts the memory available to your application to64K, emulating an older 16-bit machine. This settingshould be used at the beginning of your program only,if required. Changing this setting repeatedly will haveunpredictable effects.KAutoCompact&2enables auto-compaction on closing databases. Thiscan be slow, but it is advisable to use this setting whenlots of changes have been made to a database.KTwoDigitExponent&4enables raising of overflow errors when floating pointvalues are greater than or equal to 1.0E+100 in magnitude, instead of allowing three-digit exponents (forbackwards compatibility).KSendSwitchOnMessage&$10000enables GETEVENT, GETEVENT32, and GETEVENT32Ato return the event code $403 to ev&(1) when themachine switches on.These constants are supplied in Const.oph.By default these flags are cleared.See also GETEVENT32, CLEARFLAGS.SETHELPSets the help context to be displayedUsage: SETHELP ViewType%,HelpText$Sets the current help context.
For example, to show thehelp for the current view/state of your application (inthe main event-handler):OPL COMMAND LIST253IF (Key&=KKeyHelp32&) AND (Mods&=0)IF View%=KMainView%SETHELP KHelpView%,KMyHelpMainView$ELSEIF View%=KOtherView%SETHELP KHelpView%,KMyHelpOtherView$ELSESETHELP KHelpView%,KMyHelpQuickStart$ENDIFSHOWHELPENDIFTo ensure that a given topic is displayed if the Helpkey is pressed while a dialog is on display (you cannot‘trap’ the key itself while the dialog is on show – OPLdoes this for you):SETHELP KHelpDialog%,KMyHelpSettingsDialog$dINIT "Settings"..other dialog controls, etc.
as normal..Dia%=DIALOGTo ensure that a given topic is displayed if the Help keyis pressed while a menu is on display (again, OPL will‘trap’ the key for you):SETHELP KHelpMenu%,KMyHelpMainMenu$mINITmCARD "File",..etc....other menu controls, etc. as normal..Menu&=MENU(LastMenuValue%)See also SETHELPUID, SHOWHELP.SETHELPUIDSets the help file to be displayed by your applicationUsage: SETHELP KHelpFileUID$Sets the help file to be displayed by your application,using the unique identifier of that help file.
This UIDwould normally be the same as that of your ownapplication. It can be set on the PC using the SDK atthe time of building the help file.See also SETHELP, SHOWHELP.SETPATHSets the path for file access254OPL COMMAND LISTUsage: SETPATH name$Sets the current path for file access. For example:SETPATH "C:\Documents\"SETPATH needs the final backslash to be passed otherwise it ignores everything beyond the last backslash.LOADM continues to use the path of the initial program,but all other file access will use the new path.SHOWHELPShows the help fileUsage: SHOWHELPDisplays the help file currently associated with yourapplication, using the context most recently set bySETHELP.See also SETHELPUID, SETHELP.SINSineUsage: s=SIN(angle)Returns the sine of angle, an angle expressed in radians.To convert from degrees to radians, use the RADfunction.SIZESize of a stringUsage: S%=SIZE(String$)Returns the size of string, not just its length (to allowfor the fact that under Symbian OS all strings arestored in Unicode format).
For example, the followingcode demonstrates the difference between the SIZE andLEN keywords:PROC Main:LOCAL String$(13)String$="How Big Am I?"PRINT "Length =",LEN(String$)PRINT "Size =",SIZE(String$)PRINT "Press any key to continue."GETENDPThis should result in the following console output:OPL COMMAND LIST255Length = 13Size = 26Press any key to continueSee also LEN.SPACEGets space available on the current file’s deviceUsage: s&=SPACEReturns the number of free bytes on the device onwhich the current (open) data file is held.SQRSquare rootUsage: s=SQR(x)Returns the square root of x.STDStandard deviationUsage: s=STD(list)ors=STD(array(),element)Returns the standard deviation of a list of numeric items.The list 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=STD(arr(),3) would return the standard deviation ofelements arr(1), arr(2), and arr(3).STOPStops the running programUsage: STOPEnds the running program.Note that STOP may not be used during an OPXcallback and will raise the error ‘STOP used in callback’if it is.
See Callbacks from OPX procedures.STYLESets the text window character style256OPL COMMAND LISTUsage: STYLE style%Sets the text window character style. style% can be 2for underlined, or 4 for inverse.SUMSums a list of numeric itemsUsage: s=SUM(list)ors=SUM(array(),element)Returns the sum of a list of numeric items.The list 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 argumentmust be the array name followed by (). The secondargument, separated from the first by a comma, is thenumber of array elements you wish to operate on.For example, m=SUM(arr(),3) would return the sum ofelements arr(1), arr(2), and arr(3).TANTangentUsage: t=TAN(angle)Returns the tangent of angle, an angle expressed inradians.To convert from radians to degrees, use the DEGfunction.TESTEVENTTests if an event has occurredUsage: t%=TESTEVENTReturns ‘True’ if an event has occurred, otherwisereturns ‘False’.
The event is not read by TESTEVENT – itmay be read with GETEVENT, GETEVENT32, orGETEVENTA32.Warning: It is recommended that you use eitherGETEVENT32 or GETEVENTA32 without TESTEVENTas TESTEVENT may use a lot of power, especially whenused in a loop as will often be the case.TRAPTraps errorsSection ContentsOPL COMMAND LIST257Trapping data file commandsTrapping file commandsTrapping directory commandsTrapping data entry commandsTrapping graphics commandsUsage: TRAP commandTRAP is an error handling command.