Data type & Syntax extensions in Harbour
In addition to Clipper’s scalar ( Character, Number, Date, Logical, MEMO, Nil ) and complex ( array, CodeBlock ) data types; Harbour has extended data types: pointer as scalar and object and hach as complex type.
For standard data types please refer here and/or here.
In database files (tables) data types of fields are predefined in structure of table.
For extended field types please refer here.
For data items other than fields (such as variables and manifest constants); in general, type of data determined automatically by system, when assigning a value. The first basic way of this, is assigning a “literal” value.
For a working sample about constants please refer here.
cString := "This is a string" // A character string enclosed by a string delimiter nNumber := 123.45 // A numeric value combined digits, decimal point and a sign ( + / - ) lTrue := .T. // A T (tYy) or F (fNn) letter enclosed by two periods (.) aArray := {} // Arrays can be assigned literally by enclosed with curly brace
In addition to this basic literal value notations, Harbour has also extended notations:
– Data Types determined by special prefixs
— 0x… : Hexadecimal constant
nNumber := 0x0A // 0x prefix implies the string as Hexadecimal String // and type of resulting value become as Numeric (N) ? nNumber, VALTYPE( nNumber ) // 10 N
— 0d… date constant
dDate_1 := 0d20121225 // 0d prefix implies the string a date string // ( instead of using CTOD() ) // and type of resulting value become as Date (D) ? dDate_1, VALTYPE( dDate_1 ) // 25.12.2012 D
– Special literal string formats
— d”…” : Date constant
dDate_2 := d"2012-12-26" ? dDate_2, VALTYPE( dDate_2 ) // 26.12.2012 D
— t”…” : Time constant
tTime_1 := dDate_2 + t”01:31:06″
? tTime_1, VALTYPE( tTime_1 ) // 26.12.2012 01:31:06.000 T
— e”…” : Escape sequences
Escape sequences are used to define certain special characters within string literals.
( Prefix by “\” escape sequence codes within that string )
The following escape sequences are available in C and C++ language :
Escape sequence Description Representation ' single quote byte 0x27 " double quote byte 0x22 ? question mark byte 0x3f backslash byte 0x5c null character byte 0x00 a audible bell byte 0x07 b backspace byte 0x08 f form feed - new page byte 0x0c n line feed - new line byte 0x0a r carriage return byte 0x0d t horizontal tab byte 0x09 v vertical tab byte 0x0b nnn arbitrary octal value byte nnn xnn arbitrary hexadecimal value byte nn unnnn arbitrary Unicode value. May result in several characters. code point U+nnnn Unnnnnnnn arbitrary Unicode value. May result in several characters. code point U+nnnnnnnn
Note that all sequences not available in Harbour.
For the new complex data type Hash, there is a literally assigning way :
hHash := { => } // => sign indicates the hash ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROCEDURE Main() SET CENT ON SET DATE GERM CLS * Data Types determined by special prefixs ** 0x... : Hexadecimal constant nNumber := 0x0A // 0x prefix implies the string as Hexadecimal String // and type of resulting value become as Numeric(D) ? nNumber, VALTYPE( nNumber ) // 10 N ** 0d... date constant dDate_1 := 0d20121225 // 0d prefix implies the string a date string // ( instead of using CTOD() ) // and type of resulting value become as Date (D) ? dDate_1, VALTYPE( dDate_1 ) // 25.12.2012 D * Special literal string formats ** d"..." : Date constant dDate_2 := d"2012-12-26" ? dDate_2, VALTYPE( dDate_2 ) // 26.12.2012 D ** t"..." : Time constant tTime_1 := dDate_2 + t"01:31:06" ? tTime_1, VALTYPE( tTime_1 ) // 26.12.2012 01:31:06.000 T ** e"..." : Escape sequences ? e"This is\na string\nformatted by\nEscape sequences \x21 /* The result : This is a string formatted by Escape sequences ! */
@ MAXROW(), 0 WAIT "EOF DTS_Exts.prg" RETURN // DTS_Exts.Main() *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~