Tuesday, June 10, 2025

new and extended commands for Harbour

5 implementation suggestions

(I implemented the first 4)

1 - Declaration & initialization. Syntax:  

LOCAL | STATIC | PUBLIC | PRIVATE <var, ...> AS <TYPE>

// <TYPE> = ARRAY, CHARACTER, DATE, HASH, LOGICAL, MEMO, NUMERIC, TIMESTAMP
// artificial: CHAR, INTEGER, DECIMAL, MONEY

features:

  • declare and initialize variables with empty value
    • DATE/TIMESTAMP allow to initialize with current date/datetime
  • some types accept arguments in variable
    • for types derived from NUMERIC, it will format the value, but is not useful at runtime
  • CHAR, INTEGER, DECIMAL, MONEY are artificial types for types C, N, N, N
  • Other AS <TYPE> are not overridden by HBUtil:
    • AS OBJECT
    • AS BLOCK
    • AS POINTER
    • AS CLASS <TName> ...

 2 - Runtime parameter validation (functions and methods) . Syntax:

FUNCTION <name>( <var> [ = <xInit> | AS <TYPE> [OPTIONAL] | AS CLASS <TName> [OPTIONAL] | AS BYREF [OPTIONAL] ] [, <varN> ...] )

// the same for:
PROCEDURE <name>( ..idem.. )
METHOD <name>( ..idem.. ) CLASS TMyClass
Automatically validates parameters according to the declared type (rule):
  • <var> = <xInit> automatic initialization (when argument is omitted), type checking
  • <var> AS <TYPE> [OPTIONAL]
    • AHASH, ARRAY, BLOCK, CHAR, CHARACTER, DATE, DECIMAL, HASH,  INTEGER, LOGICAL, MEMO, MONEY, NUMERIC, OBJECT, POINTER, TIMESTAMP
    • are artificial types for types: A (or H), C, N, N, N
  • <var> AS OLE [OPTIONAL] (shortcut for AS CLASS WIN_OLEAUTO)
  • <var> AS CLASS <TName> [OPTIONAL] check class name or ancestor
  • <var> AS BYREF [OPTIONAL] checking if the passage was by reference
  • It is also possible to validate empty values ​​for the types: A, C, D, H, M, N, T
If any rule is violated, it will throw an RTE with the description and the actual name of the parameter.

3 - REQUIRED <var, ...> RETURN | THROW. Syntax: 

REQUIRED <var, ...> [ SIGNAL <name> | EVAL <expr> ] ;
   [ RETURN [<v>] | THROW ]
This command is versatile and useful, and can be used in any context and with any type of value. Its main purpose is very simple...
If any variable is empty, execute RETURN or THROW (RTE)
REQUIRED <var, ...> [ RETURN [<v>] | THROW ]
Automatic notification to your classes when:
  • Call from METHOD implementation
  • SIGNAL/EVAL are not used
  • You enable "listening"/capturing on your class. This allows you to automate your consistency or logging processes

4 - Searches a value in another value. Syntax: 

   <v> IN <Value> // STRING, ARRAY or HASH
   
   <cSubString> IN <cString>
   <xValue> IN <aArray>
   <xKey> IN <hHash>

(works fine, but maybe it's better to implement at a low level)

5 - Functions and methods, return type validation at runtime. Syntax:

FUNCTION <name>([...]) AS <TYPE>             // OR
FUNCTION <name>([...]) AS CLASS <TName>

METHOD <name>([...]) CLASS <TName> AS <TYPE> // OR
METHOD <TName>:<name>([...]) AS CLASS <TNameX>

<TYPE> = ARRAY, HASH, AHASH, CHARACTER, DATE, TIMESTAMP, NUMERIC, OBJECT, ... just simple checks
INTEGER - simple check but convert number to integer
DECIMAL | MONEY - simple check but convert number to decimal
 
AS CLASS <TNameX> = check class name or ancestor

See:

examples compiled with harbour hbutil

 


 


 

No comments:

DBU for Windows 32/64 bits (+small features) and other alternatives

Em Windows você tem múltiplas opções para gerenciar arquivos DBF: