Harbour (programming language): Difference between revisions

Content deleted Content added
m MOS:Slashes
m I have made some important changes like the spelling errors and remove likes which pages are not available.
Line 41:
==Database support==
 
Harbour extends the Clipper Replaceable Database Drivers (RDD) approach. It offers multiple RDDs such as [[DBASE|DBF]], DBFNTX, DBFCDX, DBFDBT and DBFFPT. In Harbour multiple RDDs can be used in a single application, and new logical RDDs can be defined by combining other RDDs. The RDD architecture allows for inheritance, so that a given RDD may extend the functionality of other existing RDD(s). Third-party RDDs, like RDDSQL, RDDSIX, RMDBFCDX, [[Advantage Database Server]], and Mediator exemplify some of the RDD architecture features. DBFNTX implementation has almost the same functionality of DBFCDX and RDDSIX. NETIO and LetoDB<ref>{{cite web|url=https://sourceforge.net/projects/letodb |title=LetoDB |publisher=Sourceforge.net |access-date=2013-12-09}}</ref> provide remote access over [[Transmission Control Protocol|TCP]] protocol.
 
Harbour also offers [[ODBC]] support by means of an [[Object-oriented programming|OOP]] syntax, and [[ActiveX Data Objects|ADO]] support by means of [[OLE Automation|OLE]]. [[MySQL]], [[PostgreSQL]], [[SQLite]], [[Firebird (database server)|Firebird]], [[Oracle (database)|Oracle]] are examples of databases which Harbour can connect to.
 
xBase technologies often isare confused with a [[RDBMS]] software. Although this is true, xBase is more than a simple database system as at the same time xBase languages using purely DBF can not provide the full concept of a real RDBMS.
 
==Programming philosophy==
Unlike Java which is intended to be writewritten once, run anywhere, Harbour aims to be [[writeWrite once, compile anywhere|written once, compiled anywhere]]. As the same compiler is available for all of the above operating systems, there is no need for recodingrecording to produce identical products for different platforms, except when operating system dependent features are used. Cross-compiling is supported with [[MinGW]].
Under Microsoft Windows, Harbour is more stable but less well-documented than Clipper, but has multi-platform capability and is more transparent, customizable and can run from a USB flash drive.
 
Under Linux and Windows Mobile, Clipper source code can be compiled with Harbour with very little adaptation. Most software originally written to run on Xbase++, FlagShip, FoxPro, xHarbour and others dialects can be compiled with Harbor with some adaptation. As of 2010 many efforts have been made to turnmake the transition from other [[xBase]] dialects easier.
 
Harbour can use the following C compilers, among others:
Line 61:
[[Borland C++]],
[[Watcom C]],
[[Pelles C]] and
[[Sun Studio (software)|Sun Studio]].
 
Harbour can make use of multiple [[GraphicGraphical Terminal emulation]]s, including [[console driver]]sdrivers, and Hybrid Console/GUIs, such as GTWvt, and GTWvg.
 
Harbour supports external GUIsGUI's, free (e.g. HBQt, HWGui, MiniGUIMini-GUI (latest version based on Qt and [[QtContribs]]<ref>{{cite web |title=QtContribs - Harbour Qt Projects |url=https://sourceforge.net/projects/qtcontribs/ |website=SourceForge |language=en}}</ref>) and commercial (e.g. FiveWin, Xailer). HBQt is a library providing bindings to Qt. HBIDE application is a sample of HBQt potential.
 
Harbour is 100% Clipper-compatible<ref>{{cite web|url=https://harbour.github.io/ |title=Official Harbour page |publisher=The Harbour Project |access-date=2013-12-09}}</ref> and supports many language syntax extensions including greatly extended run-time libraries such as [[OLE Automation|OLE]], [[Blat (software)|Blat]], [[OpenSSL]], [[FreeImage]]Free Image, [[GD Graphics Library|GD]], hbtip, hbtpathy, [[PCRE]], hbmzip ([[zlib]]), hbbz2 ([[bzip2]]), [[cURL]], [[Cairo (graphics)|Cairo]], its own implementation of CA-Tools, updated NanFor libraries and many others. Harbour has an active development community and extensive third party support.
 
Any [[xBase]] language provides a very productive way to build business and data intensive applications. Harbour is not an exception.
Line 78:
Additionally, the Macro Operator may compile and execute function calls, complete assignments, or even list of arguments, and the result of the macro may be used to resolve any of the above contexts in the compiled application. In other words, any Harbour application may be extended and modified at runtime to compile and execute additional code on-demand.
 
The latest Macro compiler can compile any valid Harbour code including code to preper-process before compile.
 
Syntax:
Line 94:
is the short form of &( SomeId + "postfix" ).
 
===Object orientedOriented programmingProgramming===
 
Programming in an OOP style is a broader issue than a specific library or a specific interface, but OOP programming is something many Clipper programmers have come to expect. CA-Clipper 5.2 and especially 5.3 added a number of base classes, and a matching OOP syntax. Libraries such as [https://web.archive.org/web/20010501165630/http://appsolutions.com/Classy/ Class(y)], FivewinFieWin, Clip4Win, and TopClassTop Class provide additional OOP functionality.
 
Harbour has OOP extensions with full support for classes including inheritance, based on Class(y) syntax. OOP syntax in Harbour is very similar to that of earlier Clipper class libraries so it should be possible to maintain legacy Clipper code with minimal changes.
 
==Syntax and semanticsSemantics==
[[File:Harbour Sample Code.png|thumb|600px|Harbour code on HBIDE]]
 
Line 130:
All types can be assigned to named variables. Named variable identifiers are 1 to 63 ASCII characters long, start with <code>[A-Z|_]</code> and further consist of the characters <code>[A-Z|0–9|_]</code> up to a maximum of 63 characters. Named variables are not case sensitive.
 
'''Variables have one of the following scopes:'''
 
* {{mono|LOCAL}}: Visible only within the routine which declared it. Value is lost upon exit of the routine.
Line 141:
Due to the dynamic nature of {{mono|PRIVATE}} and {{mono|PUBLIC}} variables, they can be created and destroyed at runtime, can be accessed and modified by means of runtime macros, and can be accessed and modified by Codeblocks created on the fly.
 
===Control structuresStructures===
The basic control structures include all of the standard [[dBase]], and [[Clipper (programming language)|Clipper]] control structures as well as additional ones inspired by the [[C (programming language)|C]] or [[Java (programming language)|Java]] programming languages:
 
Line 164:
NEXT
 
* The ''...'' is a sequence of one ofor more Harbour statements, and square brackets <code>[]</code> denote optional syntax.
* The ''Var'':__enumIndex() may be optionally used to retrieve the current iteration index (1 based).
* The ''LOOP'' statement restarts the current iteration of the enclosing loop structure, and if the enclosing loop is a ''FOR'' or ''FOR EACH'' loop, it increases the iterator, moving to the next iteration of the loop.
Line 172:
In the ''FOR'' statement, the ''assignment'' expression is evaluated prior to the first loop iteration. The ''TO'' expression is evaluated and compared against the value of the control variable, prior to each iteration, and the loop is terminated if it evaluates to a numeric value greater than the numeric value of the control variable. The optional ''STEP'' expression is evaluated after each iteration, prior to deciding whether to perform the next iteration.
 
In ''FOR EACH'', the ''Var'' variable will have the value (scalar, or complex) of the respective element in the collection value. The collection expression, may be an Array (of any type or combinations of types), a Hash Table, or an Object type.
 
====IF statements====
Line 187:
The condition expression(s) has to evaluate to a ''LOGICAL'' value.
 
====SWITCH statementsStatements====
Harbour supports a SWITCH construct inspired by the C implementation of switch().
 
Line 204:
* The ''EXIT'' optional statement is the equivalent of the C statement ''break'', and if present, execution of the SWITCH structure will end when the EXIT statement is reached, otherwise it will continue with the first statement below the next CASE statement (fall through).
 
====BEGIN SEQUENCE statementsStatements====
BEGIN SEQUENCE
''...''
Line 221:
END[SEQUENCE]
 
The BEGIN SEQUENCE structure allows for a well behaved abortion of any sequence, even when crossing nested procedures/functions. This means that a called procedure/function, may issue a BREAK statement, or a Break() expression, to force unfolding of any nested procedure/functions, all the way back to the first outer BEGIN SEQUENCE structure, either after its respective END statement, or a RECOVER clause if present. The Break statement may optionally pass any type of expression, which may be accepted by the RECOVER statement to allow further recovery handinghandling.
 
Additionally the Harbour ''Error Object'' supports ''canDefault'', ''canRetry'' and ''canSubstitute'' properties, which allows error handlers to perform some preparations, and then request a ''Retry Operation'', a ''Resume'', or return a [[Value (computer science)|Value]] to replace the expression triggering the error condition.
Line 239:
[STATIC] FUNCTION ''SomeProcedureName''( ''Param1'' [, ''ParamsN''] )
 
[[Subroutine|Procedures]] and [[Function (computer science)|Functions]] in Harbour can be specified with the [[keyword (computer programming)|keyword]]s <code>PROCEDURE</code>, or <code>FUNCTION</code>. Naming rules are the same as those for ''Variables'' (up to 63 characters non-case sensitive). Both Procedures and Functions may be qualified by the scope qualifier ''STATIC'' to restrict their usage to the scope of the module where defined.
 
The ''INIT'' or ''EXIT'' optional qualifiers, will flag the procedure to be automatically invoked just before calling the application startup procedure, or just after quitting the application, respectively. [[Parameter (computer science)|Parameter]]s passed to a procedure/function appear in the subroutine as local variables, and may accept any type, including references.
Line 245:
Changes to argument variables are not reflected in respective variables passed by the calling procedure/function/method unless explicitly passed BY REFERENCE using the ''@'' prefix.
 
PROCEDURE havehas no return value, and if used in an Expression context will produce a ''NIL'' value.
 
FUNCTION may return any type by means of the RETURN statement, anywhere in the body of its definition.
Line 258:
</syntaxhighlight>
 
===Sample codeCode===
The typical "[[hello world]]" program would be:
<syntaxhighlight lang="visualfoxpro">
Line 281:
</syntaxhighlight>
 
====OOP examplesExamples====
Main procedure:
<syntaxhighlight lang="vfp">