record TFunctionRecord

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TFunctionRecord = record

Description

A TFunctionRecord is used to define a function that can be used in a TRbwParser. To use the function, you must first assign the fields of the TFunctionRecord and then call TRbwParser.Functions.Add.

  TFunctionRecord = record
    InputDataTypes: array of TRbwDataType;
    OptionalArguments: integer;
    CanConvertToConstant: boolean;
    Name: string;
    Prototype: string;
    Hidden: boolean;
    case ResultType: TRbwDataType of
      rdtDouble: (RFunctionAddr: TRbwRealFunction);
      rdtInteger: (IFunctionAddr: TRbwIntegerFunction);
      rdtBoolean: (BFunctionAddr: TRbwBooleanFunction);
      rdtString: (SFunctionAddr: TRbwStringFunction);
  end;
    

Overview

Fields

InputDataTypes: array of TRbwDataType;
OptionalArguments: integer;
OptionalType: TRbwDataType;
CanConvertToConstant: boolean;
Name: string;
Prototype: string;
Hidden: boolean;
Synonyms: array of string;
ResultType: TRbwDataType
RFunctionAddr: TRbwRealFunction
IFunctionAddr: TRbwIntegerFunction
BFunctionAddr: TRbwBooleanFunction
SFunctionAddr: TRbwStringFunction

Description

Fields

InputDataTypes: array of TRbwDataType;

InputDataTypes defines the type of data passed into the function assigned to RFunctionAddr, IFunctionAddr, BFunctionAddr, or SFunctionAddr. The data are passed in as pointers to variables of the correct type.

The length of InputDataTypes normally defines the maximum number of arguments that can be passed into the function. However, if OptionalArguments is less than 0, an unlimited number of arguments can be passed to the function and the types of all those arguments must match the type of the last member of InputDataTypes; In that case, the minimum number of required arguments is the length of InputDataTypes minus 1.

See also : TRbwDataType;

OptionalArguments: integer;

If OptionalArguments is greater than 0, some of the arguments passed to the function may be nil pointers. The nil pointers will always follow the non-nil pointers; no non-nil pointer may follow a nil pointer. The maximum number of nil pointers will be OptionalArguments.

If OptionalArguments is less than 0, the number of arguments passed to the function may be greater than the length of InputDataTypes. The minimum number of arguments is the length of InputDataTypes minus 1. If more arguments are used, the types of those arguments must correspond to the value defined in the last member of InputDataTypes or to OptionalType if no InputDataTypes are defined.

OptionalType: TRbwDataType;
 
CanConvertToConstant: boolean;

CanConvertToConstant defines whether the result of a function may be considered a constant value if all of the values passed to the function in the values array are constants.

Normally CanConvertToConstant should be set to True but if the function makes reference to global variables that may change between one evaluation of the expression and the next, CanConvertToConstant should be set to False.

Pi is an example of a function for which CanConvertToConstant should be true.

CanConvertToConstant is used when optimizing compiled expressions.

Example:

        var
          // ... others omitted in example.
          PiFunction : TFunctionRecord;
          SinFunction : TFunctionRecord;
      

Pi is a constant so CanConvertToConstant is true. Pi has no input variables so it will always be converted to a constant. When PiFunction is used to create a TFunctionClass, CanConvertToConstant will set the value of the TFunctionClass.AllowConversionToConstant property. That in turn will set the value of TExpression.AllowConversionToConstant. The same happens with RFunctionAddr and InputDataTypes.

_Pi is a function defined in the implementation

        function _Pi(Values : array of pointer) : double;
        begin
          result := Pi;
        end;
      

Sin will always return the same value if it's input is a constant so CanConvertToConstant is set true. However, it will only be converted to a constant if all of it's input variables are constants.

_Sin is a function defined in the implementation

      function _Sin(Values : array of pointer) : double;
      begin
        result := Sin(PDouble(Values[0])ˆ);
      end;
      

      constructor TFunctionStringList.Create;
      begin
        inherited;
        CaseSensitive := False;
        Duplicates := dupError;
        Sorted := True;

        // ... others lines omitted in example.

        PiFunction.ResultType := rdtDouble;
        PiFunction.Name := 'Pi';
        SetLength(PiFunction.InputDataTypes, 0);
        PiFunction.OptionalArguments := 0;
        PiFunction.CanConvertToConstant := True;
        PiFunction.RFunctionAddr := _Pi;
        Add(PiFunction);

        // ... others lines omitted in example.

        PiFunction.ResultType := rdtDouble;
        PiFunction.Name := 'Pi';
        SetLength(PiFunction.InputDataTypes, 0);
        PiFunction.OptionalArguments := 0;
        PiFunction.CanConvertToConstant := True;
        PiFunction.RFunctionAddr := _Pi;
        Add(PiFunction);

        // ... others lines omitted in example.

      end;
      

Name: string;

Name is the unique identifier of the function.

Prototype: string;

Prototype should give the names and arguments for a function as they should be shown on a GUI interface. The "|" character is used to indicate the position of the function in a hierarchy.

Hidden: boolean;

Hidden determines whether or not the function should be visible in a GUI interface.

Synonyms: array of string;

Synonyms represents alternative valid spellings for the same function.

ResultType: TRbwDataType

ResultType defines the type of data returned by the function. It must correspond to the value assigned to the RFunctionAddr, IFunctionAddr, BFunctionAddr, or SFunctionAddr.

RFunctionAddr: TRbwRealFunction

RFunctionAddr is the address of the TRbwRealFunction that is to be evaluated.

IFunctionAddr: TRbwIntegerFunction

IFunctionAddr is the address of the TRbwIntegerFunction that is to be evaluated.

BFunctionAddr: TRbwBooleanFunction

BFunctionAddr is the address of the TRbwBooleanFunction that is to be evaluated.

SFunctionAddr: TRbwStringFunction

SFunctionAddr is the address of the TRbwStringFunction that is to be evaluated.


Generated by PasDoc 0.12.1 on 2013-05-13 15:41:59