### LEN Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Examples demonstrating how to get the length of a string or the size of an array. ```Harbour ? Len( "Harbour" ) --> 7 ? Len( { "One", "Two" } ) --> 2 ``` -------------------------------- ### TOKENINIT usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/token2.txt Examples demonstrating various ways to initialize a token environment using TOKENINIT. ```xHarbour tokeninit (cString) // tokenize the string with default // rules and store the token environment globally // and eventually delete an old global TE tokeninit (@cString) // no difference in result, but eventually faster, // since the string must not be copied tokeninit() // rewind counter of global TE to 1 tokeninit ("1,2,3",",",1) // tokenize constant string, store in global TE tokeninit (cString,,1,@cTE1) // tokenize cString and store TE in // cTE1 only without overriding global TE tokeninit (cString,,1,cTE1) // tokenize cString and store TE in // GLOBAL TE since 4th parameter is // not given by reference !!! tokeninit (,,,@cTE1) // set counter in TE stored in cTE1 to 1 ``` -------------------------------- ### Build xHarbour Compiler Example Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/xHarbour-xBuild/Readme.txt Example command to build the complete xHarbour compiler from source files. ```bash xbuild.exe xbp_bin\xhb.exe source\compiler\harbour.sly source\common\*.c source\compiler\*.c source\pp\*.c -oxbp_obj -ixbp_obj ``` -------------------------------- ### DISKFORMAT Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/diskutil.txt Examples demonstrating how to use DISKFORMAT to format floppy disks with various parameters. ```xHarbour DiskFormat() --> Format disk "A" to maximum capacity. DiskFormat("B","Test") --> Format disk "B" with "Teste" label. DiskFormat("A","",.T.) --> Quick format the disk "A" without a label. DiskFormat("B",,,720) --> Full format the disk "A" with 720 K bytes. ``` -------------------------------- ### DISKFREE Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/diskutil.txt Example demonstrating how to check if there is enough space on a disk to copy a database file. ```xHarbour Required := DBFSIZE() // Database size IF DISKFREE("A") < Required ? "Insufficient disk space for copying!" ENDIF ``` -------------------------------- ### Install zlib Library Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/ZipArchive/Readme.txt Commands to build and install the zlib library from the source subdirectory. ```bash make make install ``` -------------------------------- ### __TYPEFILE() function examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/file.txt Examples demonstrating how to display file contents using the __TYPEFILE() function. These examples assume the file MyText.DAT exists. ```xHarbour // display MyText.DAT file on screen __TYPEFILE( "MyText.DAT" ) // display MyText.DAT file on screen and printer __TYPEFILE( "MyText.DAT", .T. ) // display MyText.DAT file on printer only SET CONSOLE OFF __TYPEFILE( "MyText.DAT", .T. ) SET CONSOLE ON ``` -------------------------------- ### Create Progress Bar Examples Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/gtwvw/doc/funclist.txt Examples demonstrating how to create horizontal progress bars with default and custom offsets. ```xHarbour WVW_PGcreate( , 5, 10, 5, 30) :: creates horiz progressbar on current window at (5,10) to (5,30) colors using default ones. WVW_PGcreate( , 5, 10, 5, 30, {-1, 0, +1, 0} ) :: same as above, but the bar is enlarged 1 pixel to the top and 1 pixel to the bottom ``` -------------------------------- ### Install xHarbour Source: https://github.com/xharbour-org/xharbour/blob/main/doc/howto_macosx.txt Execute the installation script, which requires root access. ```bash make_gnu.sh install ``` -------------------------------- ### __dbCopyStruct() Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/dbstrux.txt Examples demonstrating how to create a new database file with the same structure as the current one, or a subset of fields using an array. ```xHarbour // Create a new file that contain the same structure USE TEST __dbCopyStruct( "MyCopy.DBF" ) // Create a new file that contain part of the original structure LOCAL aList USE TEST aList := { "NAME" } __dbCopyStruct( "OnlyName.DBF", aList ) ``` -------------------------------- ### ADSCONNECT60 Example Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/rdd_ads/doc/en/adsfuncs.txt Example of connecting to an Advantage Database server and creating a user within the session. ```xHarbour IF adsConnect60("xharbour.add", 7/* All types of connection*/, "ADSSYS", "",) // Add one user AdsDDCreateUser(, "Luiz", "papael", "This is luiz User") ENDIF ``` -------------------------------- ### ORDCREATE usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/rddord.txt Examples showing how to create an order using different RDD drivers like DBFNDX and DBFCDX. ```xHarbour USE TESTS VIA "DBFNDX" NEW ORDCREATE( "FNAME",, "Tests->fName" ) ``` ```xHarbour USE TEsts VIA "DBFCDX" NEW ORDCREATE( , "lName", "tests->lName" ) ``` -------------------------------- ### On-demand XBScript Installation Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/xHarbour-XBScript/Install scripts/Files/docs/readme.txt Include an OBJECT tag in your HTML to allow users to download and install XBScript transparently. ```html ``` -------------------------------- ### CHARSORT() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/charsort.txt Examples demonstrating various ways to use the CHARSORT() function with different parameters. ```xHarbour ? CHARSORT("qwert") // "eqrtw" ? CHARSORT("qwert", 2) // "erqwt" ? CHARSORT("b1a4a3a2a1", 2, 1) // "a2a1a3a4b1" ? CHARSORT("XXXqwert", 1, 1, 3) // "XXXeqrtw" ? CHARSORT("b1a4a3a2a1", 2, 1, 0, 1) // "a1b1a2a3a4" ? CHARSORT("384172852", 1, 1, 0, 0, 4) // "134872852" ? CHARSORT("qwert", .T.) // "wtrqe" ``` -------------------------------- ### STRDIFF() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/strdiff.txt Examples demonstrating the penalty point calculations for various string transformation scenarios. ```xHarbour ? strdiff("ABC", "ADC") // 3, one character replaced ? strdiff("ABC", "AEC") // 3, dito ? strdiff("CBA", "ABC") // 6, two characters replaced ? strdiff("ABC", "AXBC") // 1, one character inserted ? strdiff("AXBC", "ABC") // 6, one character removed ? strdiff("AXBC", "ADC") // 9, one character removed and one replaced ``` -------------------------------- ### WVW_XBcreate usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/gtwvw/doc/funclist.txt Examples showing how to create a vertical scrollbar on the current window with default and custom pixel offsets. ```xHarbour WVW_XBcreate( , 1, 10, 70, 12) :: creates Vertical scrollbar on current window at (10,70) with length 12 dimensions using default ones. buttons/parts behaviour using default ones. ``` ```xHarbour WVW_XBcreate( , 1, 10, 70, 12, {0, +5, 0, +5} ) :: creates Vertical scrollbar on current window at (10,70) with length 12 left and right coordinate is shifted 5 pixels to the right. buttons/parts behaviour using default ones. ``` -------------------------------- ### ATREPL() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/atrepl.txt Examples demonstrating basic string replacement, limiting the number of replacements, and using the mode toggle to target specific occurrences. ```xHarbour ? ATREPL("ABC", "ABCDABCDABC", "xx") --> "xxDxxDxx" ? ATREPL("ABC", "ABCDABC", "ZYXW") --> "ZYXWDZYXW" ? ATREPL("ABC", "ABCDABCDABC", "xx", 2) --> "xxDxxDABC" ? ATREPL("ABC", "ABCDABCDABC", "xx", 2, .T.) --> "ABCDxxDABC" ``` -------------------------------- ### AT() Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Locates the starting position of the first occurrence of a substring within a main string. ```xHarbour QOUT( "at( 'cde', 'abcdefgfedcba' ) = '" +; at( 'cde', 'abcsefgfedcba' ) + "'" ) ``` -------------------------------- ### FCREATE() Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/file.txt Demonstrates creating a new file and checking if the operation was successful by verifying the returned handle. ```xHarbour IF (nh:=FCREATE("TEST.TXT") <0 ? "Cannot create file" ENDIF ``` -------------------------------- ### RAT() Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Searches for the first occurrence of a substring starting from the right side of the main string. ```xHarbour QOUT( "rat( 'cde', 'abcdefgfedcba' ) = '" +; rat( 'cde', 'abcsefgfedcba' ) + "'" ) ``` -------------------------------- ### DBCREATE Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/rdddb.txt Demonstrates creating a new database file named 'testdbf' using the DBFCDX driver and a defined structure array. ```xHarbour function main() local nI, aStruct := { { "CHARACTER", "C", 25, 0 }, ; { "NUMERIC", "N", 8, 0 }, ; { "DOUBLE", "N", 8, 2 }, ; { "DATE", "D", 8, 0 }, ; { "LOGICAL", "L", 1, 0 }, ; { "MEMO1", "M", 10, 0 }, ; { "MEMO2", "M", 10, 0 } } REQUEST DBFCDX dbCreate( "testdbf", aStruct, "DBFCDX", .t., "MYALIAS" ) RETURN NIL ``` -------------------------------- ### Get file count with HB_GETUNZIPFILE Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/zipnew.txt Retrieves the number of files in a zip archive. The first example shows basic usage, while the second demonstrates integration with a progress gauge. ```Harbour FUNCTION MAIN() Local nFiles := HB_GETUNZIPFILE( "test.zip" ) if nFiles > 0 ? "This files Contains ", nfiles endif Return Nil ``` ```Harbour Function Main() Local aGauge, nLen aGauge := GaugeNew( 5, 5, 7, 40, "W/B", "W+/B" ,"" ) GaugeDisplay( aGauge ) nLen := HB_GETUNZIPFILE( "test22" ) HB_UNZIPFILE( "test22", {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ), qout(cFile) }, .t. ) Return Nil ``` -------------------------------- ### Build Using Project File Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/xHarbour-xBuild/Readme.txt Command to build using a previously generated .xbp project file. ```bash xbuild mymain.exe.xbp ``` -------------------------------- ### @...Get Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/sayget.txt Creates a GET object and displays it to the screen. ```APIDOC ## @...Get ### Description Creates a GET object and displays it to the screen. The command adds the GET object to the reserved array variable named GETLIST[]. ### Syntax @ , [SAY [PICTURE ] COLOR ] GET [PICTURE ] [WHEN ] [COLOR ] [VALID / RANGE ,] ### Arguments - **nRow** (numeric) - The row coordinate. - **nCol** (numeric) - The column coordinate. - **cSay** (character) - Message to display. - **cSayPict** (character) - Character expression of PICTURE displayed. - **cSayColor** (character) - Color to be used for the SAY expression. - **xVar** (variable/field) - An variable/field name. - **cGetPict** (character) - Character expression of PICTURE to get. - **lWhen** (logical/codeblock) - Logical expression to allow GET. - **lValid** (logical/codeblock) - Logical expression to validate GET input. - **xStart** (date/numeric) - Lower RANGE value. - **xEnd** (date/numeric) - Upper RANGE value. - **cGetColor** (character) - Color string to be used for the GET expression. ### Returns None ``` -------------------------------- ### View configure help options Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/gd/doc/index.html Run this command to see available configuration options if errors occur during the build process. ```bash ./configure --help ``` -------------------------------- ### FOPEN() Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/file.txt Demonstrates opening a file with a specific mode and checking for errors using the returned handle. ```xHarbour IF (nH:=FOPEN('X.TXT',66) < 0 ? 'File can't be opened' ENDIF ``` -------------------------------- ### TYPE command examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/file.txt Examples of using the TYPE command to display file contents to the console, printer, or an alternate file. These examples assume the file MyText.DAT exists. ```xHarbour // display MyText.DAT file on screen TYPE MyText.DAT // display MyText.DAT file on screen and printer TYPE MyText.DAT TO PRINTER // display MyText.DAT file on printer only SET CONSOLE OFF TYPE MyText.DAT TO PRINTER SET CONSOLE ON // display MyText.DAT file on screen and into a file MyReport.txt TYPE MyText.DAT TO FILE MyReport ``` -------------------------------- ### HB_VALTOSTR Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Examples showing the conversion of scalar values to strings. ```Harbour ? HB_VALTOSTR( 4 ) ? HB_VALTOSTR( "String" ) ``` -------------------------------- ### WVW_nSetCurWindow Example Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/gtwvw/doc/funclist.txt Demonstrates how to switch the current window context and restore the previous one. ```xHarbour saved := WVW_nSetCurWindow(0) ? "This will be displayed in Main Window" WVW_nSetCurWindow(saved) ``` -------------------------------- ### DESCEND Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Example showing how to use DESCEND to seek in a descending index. ```Harbour // Seek for Smith in a descending index SEEK DESCEND( "SMITH" ) ``` -------------------------------- ### EMPTY Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/string.txt Example showing the use of EMPTY to check if a string is empty. ```Harbour ? Empty( "I'm not empty" ) ``` -------------------------------- ### Macro List Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/clipper.txt Examples of comma-separated list macros supported by Harbour. ```Harbour { &cMacro } // Literal array elements list. SomeArray[ &cMacro ] // Array index list. SomeFun( &cMacro ) // Arguments list. ( &cMacro ) // parenthesized list expression. ``` -------------------------------- ### hb_gtInit Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/hb_apigt.txt Initializes the terminal environment. ```APIDOC ## hb_gtInit ### Syntax `void hb_gtInit( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr )` ### Description Initializes the terminal API with the specified file descriptors for standard input, output, and error. ``` -------------------------------- ### IsLeapYr Function Header Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/hdr_tpl.txt Example of a completed function header for the IsLeapYr function. ```C /* $DOC$ * $FUNCNAME$ * IsLeapYr() * $CATEGORY$ * Dates * $ONELINER$ * Test if a date falls in a leap year. * $SYNTAX$ * IsLeapYr( [] ) --> lIsLeap * $ARGUMENTS$ * is an optional date. If not supplied is defaults to the * value returned from date(). * $RETURNS$ * TRUE if falls in a leap year, FALSE if not. * $DESCRIPTION$ * IsLeapYr() can be used to check if a given year is a leap year. * $EXAMPLES$ * // Check if it's a leap year. * * If IsLeapYr() * ? "One extra day before you get paid this Feb!!" * Else * ? "A normal year" * EndIf * $TESTS$ * valtype( IsLeapYr( date() ) ) == "L" * valtype( IsLeapYr( ctod( "" ) ) ) == "L" * valtype( IsLeapYr() ) == "L" * IsLeapYr( SToD( "20000101" ) ) * !IsLeapYr( SToD( "19000101" ) ) * IsLeapYr( SToD( "19841231" ) ) * !IsLeapYr() * $STATUS$ * C * $COMPLIANCE$ * IsLeapYr() works exactly like CA-Clipper's IsLeapYr(), if your * CA-Clipper doesn't have such a function you're probably in a * different universe from the author of this function. * $PLATFORMS$ * All * $FILES$ * * $SEEALSO$ * Date() IsWeekend() IsHarbourFinished() IsApocalypse() * $END$ */ ``` -------------------------------- ### TOKENLOWER() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/token1.txt Examples demonstrating how to convert the first letter of tokens to lowercase. ```xHarbour ? tokenlower("Hello, World, here I am!") // "hello, world, here i am!" ? tokenlower("Hello, World, here I am!",,3) // "hello, world, here I am!" ? tokenlower("Hello, World, here I am!",",",3) // "hello, World, here I am!" ? tokenlower("Hello, World, here I am!"," W") // "hello, World, here i am!" ``` -------------------------------- ### OS() Function Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/misc.txt Displays the current operating system. ```xHarbour ? OS() ``` -------------------------------- ### hb_vmInit Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/hb_vm.txt Initializes the virtual machine. ```APIDOC ## hb_vmInit ### Description Initializes the virtual machine. ### Syntax `void hb_vmInit( BOOL bStartMainProc )` ### Arguments - **bStartMainProc** (BOOL) - Flag to start the main procedure. ``` -------------------------------- ### ADSCACHEOPENTABLES Example Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/rdd_ads/doc/en/adsfuncs.txt Example of setting the global cache limit for open tables to 25. ```xHarbour AdsCacheOpenTables( 25 ) ``` -------------------------------- ### Load XBM image from file Source: https://github.com/xharbour-org/xharbour/blob/main/contrib/gd/doc/index.html Demonstrates opening an XBM file, creating an image from it, and destroying the image after use. ```c ... inside a function ... gdImagePtr im; FILE *in; in = fopen("myxbm.xbm", "rb"); im = gdImageCreateFromXbm(in); fclose(in); /* ... Use the image ... */ gdImageDestroy(im); ``` -------------------------------- ### Creating and Populating a Hash Source: https://github.com/xharbour-org/xharbour/blob/main/doc/hash.txt Demonstrates how to initialize an empty hash and populate it with key-value pairs, including updating existing values. ```xHarbour LOCAL hHash := {=>} hHash[ 'first key' ] := 'first value' hHash[ 'second key' ] := 'second value' hHash[ 'third key' ] := 'third value' hHash[ 'second key' ] := 'NEW second value' ``` -------------------------------- ### HB_SetKeyCheck usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/set.txt Examples showing how to use HB_SetKeyCheck within ReadModal and TBrowse handlers. ```xHarbour // within ReadModal() if HB_SetKeyCheck( K_ALT_X, GetActive() ) ... // some other processing endif // within TBrowse handler case HB_SetKeyCheck( nInkey, oTBrowse ) return case nInKey == K_ESC ... // some other processing ``` -------------------------------- ### DTOR Function Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/trig.txt Examples demonstrating the conversion of degrees to radians using the DTOR function. ```xHarbour ? dtor (180) --> PI() ? dtor (60) --> PI()/3 ``` -------------------------------- ### Creating a database from a structure extended file Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/dbstrux.txt Example demonstrating how to create a new structure extended file, populate it with field definitions, and then use it to create a new database file. ```xHarbour // CREATE a new structure extended file, append some records and // then CREATE FROM this file a new database file __dbCreate( "template" ) DBAPPEND() FIELD->FIELD_NAME := "CHANNEL" FIELD->FIELD_TYPE := "N" FIELD->FIELD_LEN := 2 FIELD->FIELD_DEC := 0 DBAPPEND() FIELD->FIELD_NAME := "PROGRAM" FIELD->FIELD_TYPE := "C" FIELD->FIELD_LEN := 20 FIELD->FIELD_DEC := 0 DBAPPEND() FIELD->FIELD_NAME := "REVIEW" FIELD->FIELD_TYPE := "C" // this field is 1000 char long FIELD->FIELD_LEN := 232 // 1000 % 256 = 232 FIELD->FIELD_DEC := 3 // 1000 / 256 = 3 DBCLOSEAREA() __dbCreate( "TV_Guide", "template" ) ``` -------------------------------- ### RTOD Function Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/trig.txt Examples demonstrating the conversion of radians to degrees using the RTOD function. ```xHarbour ? rtod (PI()) --> 180 ? tanh (PI()/3) --> 60 ``` -------------------------------- ### SetKey and SET KEY command usage Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/set.txt Examples demonstrating assigning action blocks to keys, restoring previous key assignments, and using conditional code blocks. ```xHarbour local bOldF10 := setKey( K_F10, {|| Yahoo() } ) ... // some other processing Set Key K_F10 to bOldF10) ... // some other processing bBlock := SetKey( K_SPACE ) if bBlock != NIL ... // make F10 exit current get, but only if in a get - ignores other // wait-states such as menus, achoices, etc... SetKey( K_F10, {|| GetActive():State := GE_WRITE },; {|| GetActive() != NIL } ) ``` -------------------------------- ### CHARSUB Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/charop.txt Examples demonstrating the subtraction of ASCII values of corresponding characters between two strings. ```xHarbour ? charsub ("012345678", chr(1)) --> "/01234567" ? charsub ("123456789", chr(255)) --> "23456789:" ? charsub ("9999", chr(0)+chr(1)+chr(2)+chr(3)) --> "9876" ``` -------------------------------- ### Initialize Logging Channels Source: https://github.com/xharbour-org/xharbour/blob/main/doc/hblog.txt Example of initializing the standard logger with console and syslog channels and setting an application name. ```xHarbour INIT LOG ON CONSOLE() SYSLOG( HB_LOG_INFO, 0xfff19231 ) NAME "Myapp" ``` -------------------------------- ### CHARADD Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/charop.txt Examples demonstrating the addition of ASCII values of corresponding characters between two strings. ```xHarbour ? charadd ("012345678", chr(1)) --> "123456789" ? charadd ("123456789", chr(255)) --> "012345678" ? charadd ("0000", chr(0)+chr(1)+chr(2)+chr(3)) --> "0123" ``` -------------------------------- ### CREATE structure extended file and database Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/dbstrux.txt This example demonstrates creating a structure extended file named 'template', populating it with field definitions, and then using it to create a new database file named 'TV_Guide'. ```xHarbour CREATE template APPEND BLANK FIELD->FIELD_NAME := "CHANNEL" FIELD->FIELD_TYPE := "N" FIELD->FIELD_LEN := 2 FIELD->FIELD_DEC := 0 APPEND BLANK FIELD->FIELD_NAME := "PROGRAM" FIELD->FIELD_TYPE := "C" FIELD->FIELD_LEN := 20 FIELD->FIELD_DEC := 0 APPEND BLANK FIELD->FIELD_NAME := "REVIEW" FIELD->FIELD_TYPE := "C" // this field is 1000 char long FIELD->FIELD_LEN := 232 // 1000 % 256 = 232 FIELD->FIELD_DEC := 3 // 1000 / 256 = 3 CLOSE CREATE TV_Guide FROM template ``` -------------------------------- ### Pragma Command and Switch Mode Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/pragma.txt Demonstrates the syntax for using #pragma in both command mode and switch mode to control compiler settings like debug information. ```xharbour #pragma AddDebugInfo=Off /* Suppress debug info */ #pragma /B+ /* Add debug info from here */ ``` -------------------------------- ### Link Application with Installed Library Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/ZipArchive/Readme.txt Command to link the application when the library is installed in system directories. ```bash g++ $I/usr/include/ziparchive -o app app.cpp -lstdc++ -lz -lziparch ``` -------------------------------- ### SetKey usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/set.txt Demonstrates assigning, restoring, checking, and conditionally triggering code blocks for specific keys. ```xHarbour local bOldF10 := setKey( K_F10, {|| Yahoo() } ) ... // some other processing SetKey( K_F10, bOldF10 ) ... // some other processing bBlock := SetKey( K_SPACE ) if bBlock != NIL ... // make F10 exit current get, but only if in a get - ignores other // wait-states such as menus, achoices, etc... SetKey( K_F10, {|| GetActive():State := GE_WRITE },; {|| GetActive() != NIL } ) ``` -------------------------------- ### Check Drive Readiness with DISKREADY Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/diskutil.txt This example demonstrates waiting for a disk to be ready in drive A: before proceeding with a copy operation. ```xHarbour DO Copy // Call copy procedure ? "Please insert a disk in Drive A:!" DO WHILE .NOT. DISKREADY("A") *... ENDDO DO Copy // Call copy procedure ``` -------------------------------- ### Literal Curly Bracket Example {,6} Source: https://github.com/xharbour-org/xharbour/blob/main/doc/regex.txt An example of a pattern that is treated as a literal string rather than a quantifier. ```regex {,6} ``` -------------------------------- ### BROWSE() database navigation Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/browse.txt A basic example demonstrating how to open a database file and initiate the BROWSE() function. ```xHarbour // this one shows you how to browse around USE Around BROWSE() ``` -------------------------------- ### ORDDESTROY usage example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/rddord.txt Example showing how to remove an order from an order bag using the DBFCDX driver. ```xHarbour USE TEsts VIA "DBFCDX" NEW ORDdestroy( "lName", "tests" ) ``` -------------------------------- ### hb_vmInit C Prototype Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/hb_vm.txt Initializes the Harbour virtual machine. ```c #include hb_vmInit( BOOL bStartMainProc ) --> void ``` -------------------------------- ### NUMTOKEN() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/token1.txt Examples showing how to count the number of tokens in a string based on specified delimiters. ```xHarbour numtoken ("Hello, World!") == 2 numtoken ("This is good. See you! How do you do?",".!?") == 3 numtoken ("one,,three,four,,six",",",1) == 6 ``` -------------------------------- ### Initialize portable service-like startup Source: https://github.com/xharbour-org/xharbour/blob/main/xdiff.txt Configures the process to run in the background and processes tasks in the main application loop. ```xHarbour HB_Service( .T. ) HB_ServiceLoop() ``` -------------------------------- ### TOKEN() Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/token1.txt Examples demonstrating how to extract tokens from a string using various delimiters and parameters. ```xHarbour ? token ("Hello, World!",,2,1) --> "" ? token ("Hello, World!",",",2,1) --> " World!" ? token ("Hello, World!"," ",2,1) --> "World!" ``` -------------------------------- ### Create and Write Archive from Memory Source: https://github.com/xharbour-org/xharbour/blob/main/xHarbourBuilder/ZipArchive/Readme.txt This example demonstrates creating an archive in memory using CZipMemFile, then writing the resulting buffer to a disk file. ```cpp CZipArchive zip; CZipMemFile mf; // create archive in memory zip.Open(mf, CZipArchive::zipCreate); // ... // add some files to archive here e.g. by calling CZipArchive::AddNewFile // ... zip.Close(); // write the archive to disk CZipFile f; if (f.Open("c:\\temp.zip", CZipFile::modeWrite|CZipFile::modeCreate, false) { int iLen = mf.GetLength(); BYTE* b = mf.Detach(); f.Write(b, iLen); f.Close(); // we must free the detached memory free(b); } ``` -------------------------------- ### RANGEREM function examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/range.txt Examples demonstrating how to remove characters within a specific ASCII range from a string. ```xHarbour ? rangerem ("0","9","year2002.dbf") // "year.dbf", remove all digits ? rangerem ("9","0","year2002.dbf") // "22", testing removal from "9" to chr(255) // and from chr(0) to "0" ? rangerem ("0","9","yearcurr.dbf") // "yearcurr.dbf", test leaving string untouched ``` -------------------------------- ### __WAIT() Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/terminal.txt Demonstrates waiting for a key stroke. ```Harbour // Wait for a key stroke __Wait( "Press a key to continue" ) ``` -------------------------------- ### HB_ZIPFILE Usage Examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/zipnew.txt Examples demonstrating basic file compression, compressing multiple files from an array, using compression levels with a progress block, and creating a password-protected archive with a gauge progress indicator. ```xHarbour FUNCTION MAIN() IF HB_ZIPFILE( "TEST.ZIP", "TEST.PRG" ) qout( "File was successfully created" ) ENDIF IF HB_ZIPFILE( "TEST1.ZIP", { "TEST.PRG", "c:\windows\win.ini" } ) qout( "File was successfully created" ) ENDIF IF HB_ZIPFILE( "TEST2.ZIP", { "TEST.PRG", "c:\windows\win.ini" }, 9, {|cFile,nPos,| qout(cFile) } ) qout( "File was successfully created" ) ENDIF aFiles := { "TEST.PRG", "c:\windows\win.ini" } nLen := Len( aFiles ) aGauge := GaugeNew( 5, 5, 7, 40, "W/B", "W+/B" , "" ) GaugeDisplay( aGauge ) HB_ZIPFILE( "test33.zip", aFiles, 9, {|cFile,nPos| GaugeUpdate( aGauge, nPos/nLen ) },, "hello" ) Return Nil ``` -------------------------------- ### ATNUM() usage examples Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/ct/atnum.txt Basic examples demonstrating how to find the position of specific characters within a string. ```xHarbour ? ATNUM ("!", "What is the answer ? 4 ! 5 !") -> 28 ? ATNUM ("!", "What is the answer ? 4 ! 5 ?") -> 24 ``` -------------------------------- ### Display a two-line menu with status line Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/menu.txt This example demonstrates how to define menu items using the @...PROMPT command, which is preprocessed into __AtPrompt(), and handle user selection with MENU TO. ```xHarbour SET MESSAGE TO 24 CENTER @ 10, 2 PROMPT "Sunday" MESSAGE "This is the 1st item" @ 11, 2 PROMPT "Monday" MESSAGE "Now we're on the 2nd item" MENU TO nChoice DO CASE CASE nChoice == 0 // user press Esc key QUIT CASE nChoice == 1 // user select 1st menu item ? "Guess you don't like Mondays" CASE nChoice == 2 // user select 2nd menu item ? "Just another day for some" ENDCASE ``` -------------------------------- ### ORDLISTADD Example Source: https://github.com/xharbour-org/xharbour/blob/main/doc/en/rddord.txt Demonstrates opening a database file and adding a specific order from an order bag to the current work area's order list. ```xHarbour USE Customer VIA "DBFCDX" NEW ORDLISTADD( "Customer", "CuAcct" ) ```