Tool Properties

Author: Optuma Team Last updated: Oct 16, 2019 14:41

Introduction

Tool Properties are developer defined properties that can be shown in the properties panel and can be set by the user and used in the programming of the tool. To add a custom tool property, call the Add.. function on a tool E.g. Tool.AddBoolean().

The following lists the Tool Properties that can be added to a tool.

function AddInteger(sName, sCaption : String; iDefault : Integer) : TIntegerProperty;
function AddBoolean(sName, sCaption : String; bDefault : Boolean) : TBooleanProperty;
function AddList(sName, sCaption: String; sItems : String; iDefaultIndex: Integer) : TListProperty;
function AddReal(sName, sCaption : String; rDefault : Real) : TRealProperty;
function AddHeading(sName, sCaption : String) : THeadingProperty; <br></br>function AddDate(sName, sCaption : String, default : TDateTime) : TDateProperty;

Running code when the property changes

To run code when the property is changed by a user we create a OnPropertyChange procedure which will get called automatically, passing the variable that changed.

procedure OnPropertyChange(aVar : TProperty);
begin
  if aVar.Name = 'VARNAME' then
  begin
     // do something with aVar which is the property that changed
  end;
end;

Integer Tool Property

Adding an Integer Tool Property

To add a tool property we first need to declare the tool property variable. In this example we are creating an Integer property that we will use to set the bars on a moving average tool.

var
  aBars : TIntegerProperty;

To create the property we need to call AddInteger on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - This is the initial value of the property.
aBars := Tool.AddInteger('BARS', 'Bars', 50);

Using the Integer Tool Property

To use the value of the property we use the .Variable property to access the Integer value.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
  Plot1.Data := MA('CALC=CLOSE, BARS='+IntToStr(aBars.Variable), DataIn.Data);
end;

Boolean Tool Property

Adding an Boolean Tool Property

To add a tool property we first need to declare the tool property variable. In this example we are creating an Boolean property that we will use to show or hide the moving average tool.

var bShowTool: TBooleanProperty;

To create the property we need to call AddBoolean on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - This is the initial value of the property.
bShowTool := Tool.AddBoolean('SHOW', 'Show/Hide Plot', True);

Using the Boolean Tool Property

To run code when the property is changed by a user we create a OnPropertyChange procedure which will get called automatically, passing the variable that changed. To use the value of the property we use the .Variable property to access the Boolean value.

procedure OnPropertyChange(aVar : TProperty);
begin
  if aVar.Name = 'SHOW' then
  begin
     Plot1.Visible := TBooleanProperty(aVar).Variable;
  end;
end;

List Tool Property

Adding an List Tool Property

To add a tool property we first need to declare the tool property variable. In this example we are creating an list (drop down) property that we will use to set the calc type of the moving average tool.

var aList : TListProperty; <br></br>

To create the property we need to call AddList on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - This is the list of values of the property. The different value are separated with a character.
  • Default Index - This is the index of the initial value. Where 0 is the index for the first item in the list.
aList := Tool.AddList('LIST','Calc Type', 'CLOSE|HIGH', 0);

Using the List Tool Property

To get the string value of the list property we use the GetDisplayValue() function for the property which returns a string;

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList); 
begin 
  Plot1.Data := MA('CALC='+aList.GetDisplayValue()+', BARS=5', DataIn); 
end;

Real Tool Property

Adding a Real Tool Property

To add a real or double property we first need to declare the real property variable.

var aData: TRealProperty;

To create the property we need to call AddReal on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - This is the initial value of the property.
aData := Tool.AddReal('DATA', 'Data', 50.5);

Using the Real Tool Property

To use the value of the property we use the .Variable property to access the real value.

procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
  Print(aData.Variable)
end;

Colour Property

Adding a Colour Property

To add a colour property we first need to declare the property variable.

var Color : TColorProperty; <br></br>

To create the property we need to call AddColor on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - This is the initial color of the property.
Color := Tool.AddColor('MyColor', 'MyColor', clRed);

Using the ColorProperty

To use the value of the property we use the .Variable property to access the color.

procedure OnPropertyChange(aVar : TProperty);
begin
  if aVar.Name = 'MyColor' then
  begin
     Plot1.FillColor := TColorProperty(aVar).Variable;
  end;
end;

Heading Property

Adding a Heading Property

A heading property can be used to group other properties under a heading. To add a heading property, first declare a heading property variable.

var aHeading: THeadingProperty;

To create the property we need to call AddHeading on the Tool. The call has two parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
aHeading:= Tool.AddHeading('HEADER1','My Heading');

Using the Heading Property

To add child properties to the heading variable, call the appropriate Add… function. E.g. This will add a Integer property variable to the heading.

MyInt := aHeading.AddInteger('INT1', 'My Int', 10);

##Date Property

Adding a Date Property

A date property can be used to display a date in properties panel.

var aDate: TDateProperty;

To create the property we need to call AddDate on the Tool. The call has three parameters

  • Property Name - This is the id of the property
  • Display Name - This is the name that will be displayed in the properties panel.
  • Default Value - The default date as a TDateTime - usually now()
aDate:= Tool.AddDate('DATE1','My Date', now());

Using the Date Property

dd := Tool.AddDate('MyDate','My Date', now());           <br></br>dd.Variable := StrToDate('02/02/2018'); // uses windows short date format

You can use the StrToDate to generate a TDateTime value from a string.

Discussion