John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 29
Текст из файла (страница 29)
The Esc keywill always cancel a dialog, however, even when itcontains a multi-line edit box.The following example presents a three-line editbox that is about 10 characters wide and allows up to399 characters:CONST KLenBuffer%=399PROC dEditM:LOCAL buffer&(101)REM 101=1+(399+3)/4 in integer arithmeticLOCAL pLen&,pText&158OPL COMMAND LISTLOCAL i%LOCAL c%pLen&=ADDR(buffer&(1))pText&=ADDR(buffer&(2))WHILE 1dINIT "Try dEditMulti"dEDITMULTI pLen&,"Prompt",10,3,KLenBuffer%dBUTTONS "Done",%d REM button needed toexit dialogIF DIALOG=0 :BREAK :ENDIFPRINT "Length:";buffer&(1)PRINT "Text:"i%=0WHILE i%<buffer&(1)c%=PEEKB(pText&+i%)IF c%>=32PRINT CHR$(c%);ELSEREM just print a dot for special charactersPRINT ".";ENDIFi%=i%+1ENDWHENDWHENDPSee also dINIT.DEFAULTWINChanges the default window’s color modeUsage: DEFAULTWIN mode%Changes the default window’s color mode.
The defaultwindow has ID=1, and uses a mode specific to thehardware capabilities of the Symbian OS phone itis running on. For example, a 4-grey window (2bit, KColorDefWinWin4GrayMode%) is created ongrey-scale machines, and a 256-color (8-bit, KColorDefWin256ColorMode%) window is created on colorscreen machines.The default can be overridden using DEFAULTWIN.mode% specifies the new color mode:KColorDefWin2GrayMode%KColorDefWin4GrayMode%012-grey mode4-grey modeOPL COMMAND LISTKColorDefWin16GrayMode%KColorDefWin256GrayMode%KColorDefWin256ColorMode%23515916-grey mode256-grey mode256-color modeNote: The existing constants, KDefWin4ColorMode%and KDefWin16ColorMode%, are retained for backwards compatibility (see below).These constants are supplied in Const.oph.Using high-color mode uses more power than usingmodes with fewer colors.You are advised to call DEFAULTWIN once near thestart of your program and nowhere else if you need tochange the color mode of the default window.
If it failswith an ‘Out of memory’ error, the program can thenexit cleanly without losing vital information.DEGConverts from radians to degreesUsage: d=DEG(x)Converts from radians to degrees.Returns x, an angle in radians, as a number ofdegrees. The formula used is: 180*x/PI.All the trigonometric functions (SIN, COS, etc.) workin radians, not degrees. You can use DEG to convertan angle returned by a trigonometric function back todegrees. For example:PROC xarctan:LOCAL arg,anglePRINT "Enter argument:";INPUT argPRINT "ARCTAN of",arg,"is"angle=ATAN(arg)PRINT angle,"radians"PRINT DEG(angle),"degrees"GETENDPTo convert from degrees to radians, use RAD.DELETEDeletes filesUsage: DELETE filename$Deletes any type of file.160OPL COMMAND LISTYou can use wildcards, for example, to delete all thefiles in D:\OPL:DELETE "D:\OPL\*"See also RMDIR.DELETEDeletes a table from a databaseUsage: DELETE dbase$,table$This deletes the table table$ from the database dbase$.To do this all views of the database, and hence thedatabase itself, must be closed.FILEDefines a filename edit box or selectorUsage:dFILE var file$,p$,f%or:dFILE var file$,p$,f%, uid1&,uid2&,uid3&Defines a filename edit box or selector, to go in adialog.
A ‘Folder’ and ‘Disk’ selector are automaticallyadded on the following lines.By default no prompts are displayed for the file,folder, and disk selectors. A comma-separated promptlist should be supplied. For example, for a filenameeditor with the standard prompts use:dFILE f$,"File,Folder,Disk",1Flagsf% controls the type of file editor or selector, and thekind of input allowed. You can add together any of thefollowing values (from Const.oph):–DFileEditBox%KDFileAllowFolders%KDFileFoldersOnly%0124use a selectoruse an edit boxallow directory namesdirectory names onlyOPL COMMAND LISTDFileEditorDisallowExisting%KDFileQueryExisting%KDFileAllowNullStrings%KDFileAllowWildCards%KDFileSelectorWithRom%KDFileSelectorWithSystem%81632128256512161disallow existing filesquery existing filesallows null string inputobey/allow wildcardsallow ROM files to be selectedallow files in the System folderto be selectedThe first of the list is the most crucial.
If you add 1 intof%, you will see a file edit box, as when creating a newfile. If you do not add 1, you will see the ‘matching file’selector, used when choosing an existing file.If performing a ‘copy to’ operation, you might use1+2+16 to specify a file edit box, in which you cantype the name of a directory to copy to, and that willproduce a query if you type the name of an existing file.If asking for the name of a directory to remove, youmight use 4, to allow an existing directory name only.‘Query existing’ is ignored if ‘disallow existing’ isset. These two, as well as ‘allow null string input’, onlywork with file edit boxes, not ‘matching file’ selectors.Restriction by UIDFor file selectors, dFILE supports file restriction by UID,or by type from the user’s point of view.
Documentsare identified by three UIDs, identifying which application created the document and what kind of file itis. Specifying all three UIDs will restrict the files asmuch as is possible, and specifying fewer will provide less restriction. You can supply 0 for uid1& anduid2& if you only want to restrict the list to uid3&.This may be useful when dealing with documents fromone of your own applications: you can easily findout the third UID as it will be the UID you specified in the APP statement. Note that UIDs are ignoredfor editors. For example, if your application has UIDKUidMyApp&, then the following will list only yourapplication-specific documents:dFILE f$,p$,f%,0,KUidOplDoc&,KUidMyApp&REM KUidOplDoc& for OPL docsSome OPL-related UID values are given in Const.oph.162OPL COMMAND LISTKUidOplInterpreter&KUidOplApp&KUidOplDoc&KUidOPO&KUidOplFile&KUidOpxDll&268435575268435572268435573268435571268435594268435549the OPL interpreteran OPL appan OPL documentan OPOan OPL filean OPXYou can always press Tab to produce the full fileselector with a dFILE item.file$ must be declared to be KDFileNameLen% byteslong, since filenames may be up to this length.
If it isshorter, an error will be raised.KDFileNameLen% 255 maximum filename lengthfor dFILESee also dINIT.dFLOATDefines an edit box for a floating point numberUsage: dFLOAT var fp,p$,min,maxDefines an edit box for a floating point number, to goin a dialog.p$ will be displayed on the left side of the line.min and max give the minimum and maximumvalues that are to be allowed. An error is raised if minis higher than max.fp must be a LOCAL or a GLOBAL variable. Itspecifies the value to be shown initially. When youfinish using the dialog, the value you entered is returnedin fp.See also dINIT.DIALOGPresents a dialogUsage: n%=DIALOGPresents the dialog prepared by dINIT and commandssuch as dTEXT and dCHOICE.
If you complete thedialog by pressing Enter, your settings are stored in thevariables specified in dLONG, dCHOICE, etc., althoughyou can prevent this with dBUTTONS.If you used dBUTTONS when preparing the dialog,the keycode that ended the dialog is returned. Otherwise, DIALOG returns the line number of the item thatwas current when Enter was pressed. The top item (orthe title line, if present) has line number 1.OPL COMMAND LIST163If you cancel the dialog by pressing Esc, the variablesare not changed and KDlgCancel% is returned:KDlgCancel%0return value: dialogwas cancelledSee also dINIT.dINITInitializes a dialogUsage: any ofdINITdINIT title$dINIT title$,flags%Prepares for definition of a dialog, canceling any existing one.
Use dTEXT, dCHOICE, etc. to define each itemin the dialog, then DIALOG to display the dialog.If title$ is supplied, it will be displayed at the top ofthe dialog. Any supplied title$ will be positioned in agrey box at the top of the dialog. flags% can be anyadded combination of the following constants:KDlgButRight%KDlgNoTitle%KDlgFillScreen%KDlgNoDrag%KDlgDensePack%buttons on the right rather than at the bottomno title baruse the full screendon’t allow the dialog box to be draggedpack the dialog contents (not buttons) denselyThese constants are supplied in Const.oph. Sometimesthese values will be ignored in certain UIs.It should be noted that dialogs without titles cannotbe dragged regardless of the ‘No drag’ setting.
Densepacking enables more lines to fit on the screen forlarger dialogs.If an error occurs when adding an item to a dialog,the dialog is deleted and dINIT needs calling again.This is necessary to avoid having partially specifieddialog lines. The following code will raise a ‘Structurefault’ error:REM ** Faulty OPL fragment **dINITONERR e1REM bad arg list gives argument error:164DIR$OPL COMMAND LISTdCHOICE ch%, "ChList", "a,b,,,,c"e1::ONERR OFFdLONG l&,"Long",0,12345DIALOGLists files that match a specificationUsage: d$=DIR$(filespec$)then d$=DIR$("")Lists filenames, including subdirectory names, matching a file specification. You can include wildcards in thefile specification. If filespec$ is just a directory name,include the final backslash on the end, for example,"\TEMP\".