John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 26
Текст из файла (страница 26)
If m2$ is not supplied or if it is a nullstring, the second message line is left blank.Up to three keys may be used. b1$, b2$ and b3$are the strings (usually words) to use over the keys. b1$appears over an Esc key, b2$ over Enter, and b3$ overSpace. This means you can have Esc, or Esc and Enter, orEsc, Enter and Space keys. If no key strings are supplied,the word CONTINUE is used above an Esc key.The return value, r%, is one of the following:KAlertEsc%1Escape keyKAlertEnter%2Enter keyKalertSpace%3Space barThese constants are supplied in Const.oph.OPL COMMAND LISTALLOC137Allocates a cell on the heapUsage: pcell& = ALLOC(size&)Allocates a cell on the heap of the specified size,returning the pointer to the cell or zero if there is notenough memory.See also SETFLAGS if you require a 64K limit to beenforced on 32-bit target devices.
If the flag is setto restrict the limit, pcelln& is guaranteed to fit intoan integer.See ADJUSTALLOC, REALLOC, FREEALLOC. See alsoDynamic Memory Allocation.APPDefines an applicationUsage:APP caption,uid&...ENDABegins definition of an OPL application.caption is the application’s name (or caption) in themachine’s default language. Note that although captionis a string, it is not enclosed in quotes.uid& is the application’s UID. For distributed applications, official reserved UIDs must be used. Thesecan be obtained by contacting Symbian Ltd (see OPLapplications for details of how to do this).All information included in the APP...ENDA structure will be used to generate a.
aif file, which specifiesthe applications caption in various languages, its iconsfor use on the System screen, and its setting of FLAGS.See CAPTION, ICON, FLAGS.APPENDAdds a record to a data fileUsage: APPENDAdds a new record to the end of the current data file.The record that was current is unaffected. The newrecord, the last in the file, becomes the current record.The record added is made from the current valuesof the field variables A.field1$, A.field2$, and so on, ofthe current data file. If a field has not been assigned avalue, zero will be assigned to it if it is a numeric field,or a null string if it is a string field.138OPL COMMAND LISTExample:PROC add:OPEN "address",A,f1$,f2$,f3$PRINT "ADD NEW RECORD"PRINT "Enter name:",INPUT A.f1$PRINT "Enter street:",INPUT A.f2$PRINT "Enter town:",INPUT A.f3$APPENDCLOSEENDPTo overwrite the current record with new field values,use UPDATE.See Database File Handling for more details.
See alsoINSERT, MODIFY, PUT, CANCEL, SETFLAGS.ASCGets a character code from a stringUsage: a%=ASC(a$)Returns the character code of the first character ofa$. Alternatively, use A%=%char to find the code forchar – e.g. %X for ‘X’. If a$ is a null string ("") ASCreturns the value 0.Example: A%=ASC("hello") returns 104, the codefor h.ASINArcsineUsage: a=ASIN(x)Returns the arc sine, or inverse sine (SIN-1) of x.x must be in the range −1 to +1. The numberreturned will be an angle in radians.
To convert theangle to degrees, use the DEG function.ATPositions the text cursorUsage: AT x%,y%Positions the cursor at x% characters across the textwindow and y% rows down. AT 1,1 always moves tothe top left corner of the window. Initially, the windowis the full size of the screen, but you can change its sizeand position with the SCREEN command.OPL COMMAND LIST139A common use of AT is to display strings at particularpositions in the text window.
For example:AT 5,2 :PRINT "message".PRINT statements without an AT display at the leftedge of the window on the line below the last PRINTstatement (unless you use, or;) and strings displayed atthe top of the window eventually scroll off as morestrings are displayed at the bottom of the window.Displayed strings always overwrite anything that ison the screen – they do not cause things below themon the screen to scroll down.Example:PROC records:LOCAL k%OPEN "clients",A,name$,tel$DOCLSAT 1,7PRINT "Press a key to"PRINT "step to next record"PRINT "or Q to quit"AT 2,3 :PRINT A.name$AT 2,4 :PRINT A.tel$NEXTIF EOFAT 1,6 :PRINT "EndOfFile"FIRSTENDIFk%=GETUNTIL k%=%Q OR k%=%qCLOSEENDPATANArctangentUsage: a=ATAN(x)Returns the arc tangent, or inverse tangent (TAN-1) of x.The number returned will be an angle in radians.
Toconvert the angle to degrees, use the DEG function.BACKMoves back one record in the data file140OPL COMMAND LISTUsage: BACKMakes the previous record in the current data file thecurrent record.If the current record is the first record in the file, thenthe current record does not change.BEEPSounds the buzzerUsage: BEEP time%,pitch%Sounds the buzzer. The beep lasts for time%/32 seconds, so for a beep a second long make time%=32, etc.The maximum is 3840 (2 minutes).The pitch (frequency) of the beep is 512/(pitch%+1) kHz.BEEP 5,300 gives a comfortably pitched beep.If you make time% negative, BEEP first checkswhether the sound system is in use (perhaps by anotherOPL program) and returns if it is.
Otherwise, BEEP waitsuntil the sound system is free.Example (a scale from middle C):PROC scale:LOCAL freq,n%REM n% relative to middle An%=3REM start at middle CWHILE n%<16freq=440*2**(n%/12.0) REM middle A = freq440HzBEEP 8,512000/freq-1.0n%=n%+1IF n%=4 OR n%=6 OR n%=9 OR n%=11 ORn%=13n%=n%+1ENDIFENDWHENDPAlternatively, sound the buzzer with this statement:PRINT CHR$(7).
This produces a click sound.Note: This command is deprecated from Symbian OSv6.0 onwards. Instead, developers should look at theMediaServer OPX or similar to generate sounds.BEGINTRANSBegins a transaction on a databaseUsage: BEGINTRANSOPL COMMAND LIST141Begins a transaction on the current database. The purpose of this is to allow changes to a database to becommitted in stages. Once a transaction has beenstarted on a view (or table) then all database keywordswill function as usual, but the changes to that view willnot be made until COMMITTRANS is used.See also COMMITTRANS, ROLLBACK, INTRANS.BOOKMARKPlaces a bookmark on the current recordUsage: b%=BOOKMARKPuts a bookmark at the current record of the currentdatabase view.
The value returned can be used inGOTOMARK to make the record current again. UseKILLMARK to delete the bookmark.BREAKBreaks out of a control loopUsage: BREAKMakes a program performing a DO...UNTIL orWHILE...ENDWH loop exit the loop and immediatelyexecute the line following the UNTIL or ENDWHstatement.Example:DO...IF a=bBREAKENDIF...UNTIL a=bRem BREAK command will take you to hereX%=3BUSYBusy messageUsage: any ofBUSY str$,c%,delay%BUSY str$,c%BUSY str$BUSY OFF142OPL COMMAND LISTBUSY str$ displays str$ in the bottom left of the screen,until BUSY OFF is called.
Use this to indicate ‘Busy’messages, usually when an OPL program is going to beunresponsive to key presses for a while.If c% is given, it controls the corner in which themessage appears:KBusyTopLeft%KBusyBottomLeft%KBusyTopRight%KBusyBottomLeft%0123top leftbottom left (default)top rightbottom rightThese corner value constants are supplied in Const.oph.delay% specifies a delay time (in half seconds) beforethe message should be shown.
Use this to prevent ‘Busy’messages from continually appearing very briefly onthe screen.Only one message can be shown at a time. Themaximum string length of a BUSY message is 80 characters, given by Const.oph’s KBusyMaxtext%. An ‘Invalidargument’ error is returned for any value of str$ longerthan this.KBusyMaxtext%BYREF80maximum length of aBUSY messagePasses a variable by referenceUsage: BYREF variablePasses a variable by reference to an OPX procedurewhen used in a procedure argument list.
This meansthat the value of the variable may be changed bythe procedure.See the OPX header files for more details.CANCELCancels a database transactionUsage: CANCELMarks the end of a database’s INSERT or MODIFY phase and discards the changes made duringthat phase.CAPTIONSets an application’s captionUsage: CAPTION caption$,languageCode%OPL COMMAND LIST143Specifies an application’s public name (or caption) fora particular language, which will appear below its iconon the Extras bar and in the list of ‘Programs’ in the‘New File’ dialog (assuming the setting of FLAGS allowsthese) when the language is that used by the machine.CAPTION may only be used inside an APP...ENDAconstruct.The language code specifies for which languagevariant the caption should be used, so that the caption need not be changed when used on a differentlanguage machine. If used, for whatever language,CAPTION causes the default caption given in the APPdeclaration to be discarded.
Therefore CAPTION statements must be supplied for every language in whichthe application is liable to be used, including the language of the machine on which the application isoriginally developed.The values of the language code should be one ofthe following:KLangEnglish%KLangFrench%KLangGerman%KLangSpanish%KLangItalian%KLangSwedish%KLangDanish%KLangNorwegian%KLangFinnish%KLangAmerican%KLangSwissFrench%KLangSwissGerman%123456789101112KLangPortuguese%KLangTurkish%KLangIcelandic%KLangRussian%KLangHungarian%KLangDutch%KLangBelgianFlemish%KLangAustralian%KLangBelgianFrench%KLangAustrian%KLangNewZealand%KLangInternationalFrench%131415161718192021222324These constants are supplied in Const.oph.The maximum length of caption$ is 255 characters.However, you should bear in mind that a caption longerthan around 8 characters will not fit neatly below theapplication’s icon on the Extras bar.See APP.
See also OPL applications.CHR$Converts a character to a stringUsage: a$=CHR$(x%)Returns the character with character code x%.144OPL COMMAND LISTYou can use it to display characters not easily available from the keyboard. For example, the instructionPRINT CHR$(133) displays an ellipsis (...).CLEARFLAGSClears system flagsUsage: CLEARFLAGS flags&Clears the flags given in flags& if they have previouslybeen set by SETFLAGS, returning to the default.See SETFLAGS.CLOSECloses the current database viewUsage: CLOSECloses the current view on a database. If there are noother views open on the database then the databaseitself will be closed.
See SETFLAGS for details of howto set auto-compaction on closing files.If you’ve used ERASE to remove some records,CLOSE recovers the memory used by the deletedrecords, provided it is held either in the internal memory, or on a memory disk.CLSClears the text windowUsage: CLSClears the contents of the text window.The cursor then goes to the beginning of the topline. If you have used CURSOR OFF the cursor is stillpositioned there, but is not displayed.CMD$Command line argumentsUsage: c$=CMD$(a%)Returns the command line arguments passed whenstarting a program. Null strings may be returned. a%is one of the constant values KCmdAppName%, KCmdUsedFile%, or KCmdLetter% defined in Const.oph.CMD$(KCmdUsedFile%) and CMD$(KCmdLetter%)are only defined for OPL applications.The value returned by CMD$ and its meaningdepends on the value of a%:OPL COMMAND LISTKCmdAppName%1KCmdUsedFile%2KCmdLetter%3145returns the full path name used to startrunning the programreturns the full path name of the file tobe used by an OPL application.
Forexample, if CMD$(3)=R (see below), adefault filename, including path, ispassed in CMD$(2)returns one of the values below, andindicates the kind of command thatwas used to start the applicationIf an application passes KCmdLetter% to CMD$, thereturn value is one of:KCmdLetterCreate$"C"application was started as a result of aCreate new file command in the shellKCmdLetterOpen$"O"application was started by opening afile belonging to it in the systemscreenKCmdLetterRun$"R"application was run directly from theExtras bar, by opening the applicationitself in the system screen, or from theProgram editorThe constants are defined in Const.oph.See also GETCMD$ and OPL applications.COMMITTRANS Commits the current database transactionUsage: COMMITTRANSCommits the transaction on the current view.See also BEGINTRANS, ROLLBACK, INTRANS.COMPACTCompacts a database fileUsage: COMPACT file$Compacts the database file$, rewriting the file in place.All views on the database and hence the file itselfshould be closed before calling this command.