Chain of Command Notes - arp6333/xplusplus GitHub Wiki
Extension Classes begin with the keyword 'final', and their names end with '_Extension'; example with the 'SalesEditLines' form:
final class SalesEditLines_Extension
{
...
}
Above this, we use the 'ExtensionOf' to declare what it is we are extending:
[ExtensionOf(...)]
final class SalesEditLines_Extension
{
...
}
Class: classStr(-NameOfBaseClass-)
Table / Data entity: tableStr(-NameOfBaseTable-)
Form: formStr(-NameOfBaseForm-)
Form Datasource: formDataSourceStr(-NameOfBaseForm-, -NameOfDataSource-)
Form Data field: formDataFieldStr(-NameOfBaseForm-, -NameOfDataSource-, -NameOfField-)
Form control: formControlStr(-NameOfBaseForm-, -NameOfControl-)
Example functionality:
/// <summary>
/// Example Extension of a form DataSource.
/// Here, are extending the SalesParmLine DataSource in the SalesEditLines Form.
/// </summary>
[ExtensionOf(formDataSourceStr(SalesEditLines, SalesParmLine))]
final class SalesEditLinesSalesParmLine_Extension
{
/// <summary>
/// Random extendable method chosen for example.
/// </summary>
public void selectionChanged()
{
// 'next' keyword is required to continue the chain
// It does not have to be at the beginning; it can be before, after, or anywhere in-between our code depending on desired use case
next selectionChanged();
// If the method has a return value, we can set it to a variable and return it later, like such:
bool result = next selectionChanged();
// ... our code here, which could include modifying the value of 'result' ...
return result;
// Getting the extended datasource / control
// 'this' keyword will all depend on what exactly you are extending
// (extending DS, this = datasource; extending form control, this = form control; etc)
FormDataSource formDS = any2Object(this) as FormDataSource;
FormControl control = any2Object(this) as FormControl;
// Getting the currently selected table record, if applicable
SalesParmLine SalesParmLine = formDS.cursor();
// Get the form run - we can then use this can extract lots of information from the form such as other controls and datasources
FormRun formRun = control.formRun(); // or formDS.formRun()
// Get another datasource from the same parent form
// formRun.dataSource(formDataSourceStr(-FormName-, -DataSourceName-))
FormDataSource SalesParmTableDS = formRun.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable));
// Get a control from the parent form
// formRun.design().controlName(formControlStr(-FormName-, -ControlName-))
// We can use the 'as' keyword to assign it to any type of FormControl, this example just uses the FormDateControl
FormDateControl dateControl = formRun.design().controlName(formControlStr(SalesEditLines, DateControl)) as FormDateControl;
// To access a form variable, you can use 'element'
// For example, if the main form has a variable declared 'str stringVariable' it can be retrieved in the extension using:
str stringVariable = element.stringVariable;
}
}