Using FastScript within FastCube componentsWhat is FastScript
FastScript is a scripting library. It is useful for the programmers who want to add scripting ability to their projects. FastScript is written on 100% Object Pascal and can be installed in popular versions of Delphi and C++Builder. Unique feature of FastScript is ability to use several languages (PascalScript, C++Script,JScript and BasicScript), so you can write scripts using your favourite language.FastScript doesn't use Microsoft Scripting Host, so it can be used in Windows and Linux environment.
FastScript offers plenty of options and using scenarios but we'll focus on some examples how to add new necessary functions and use them later within FastCube component.What is FastCube
As you probably know, FastCube is set of professional components for business intelligence and data mining. It allows - relatively simply - to provide application users with powerful, flexible and fast tool for creating variable data views, for instance:
- cross tables
- quick data sheets
- multidimensional data views
- table and graph data layouts
FastScript is equipped with tens of built-in functions but there are certain cases when they are insufficient and special function is necessary to be added. Now we show how to do it in couple of minutes.Creating new function in FastScript
Let's have a case when we need to determine if given person is adult currently. It means we'll compare her/his birthday with an actual date and in relationship with function result we say "person is actually adult (is at least 18 years old") or not.
We decided new function will be added into FS_ISYSRTTI.PAS unit. It contains some predefined datetime, numeric, string and other functions so we will widen set of those which regard date and time. First of all, we'll create new function code:
function IsAdult(Born, Actual: TDateTime) :Integer; begin try if IncYear(Born,18)>=Actual then Result:=0 else Result:=1; except Result:=-1; end; end;
New function has been created but we have to do some steps for making it visible from the outside. Let's add function declaration into Create constructor:
constructor TfsSysFunctions.Create(AScript: TfsScript);
with AScript do begin .. AddMethod('function IsAdult(Born,Actual: TDateTime): Integer', CallMethod4, FCatDate);
As you can see, new function uses CallMethod4 declaration because of being date/time based. Third and probably last step is to extend function TfsSysFunctions.CallMethod4 with newly created function IsAdult:
if MethodName = 'ISADULT' then Result := IsAdult(Caller.Params,Caller.Params)
Declaration of new function can be placed wherever inside TfsSysFunctions.CallMethod4 body.
Using new function together with FastCube
Standard work with FastCube is based on placing dimensions on the axis X and Y of the analysis and consequent creating measures (they are calculated at realtime using actual data) which have no filter set. For instance, if we have a field called Date_of_birth, we are not able to separate certain groups of records (such as adult people or kids under 6 years) without using filter.
However, we are aware of new IsAdult function so we can create appropriate filter with help of added function. In analysis window, click the Measure Editor button on the toolbar. Measure Editor dialog contaning several tabs appears. Click the Filter tab and double click field Function - Formula Editor is now displayed.
Now you can write required script which will FastCube use for filtering records as is depicted on the image.
Second image shows how new function IsAdult is available in Functions tree in section DateTime (Datum a čas).
About the AuthorIng. Karel Janeček, MBA, MSc.
More interesting links and pages
Visit GambleGenie.fi to get the best casino value in Finland
If you are going to play online casino in Canada you better visit the Genie first
Discover UK licensed casino sites at Casinopilot
Try out new casino sites at SmartphoneCasinos.co.uk
Indian casinos are here to stay and Royal Panda is your top choice
Play blackjack at the best live dealer casino online in the UK
Our favorite online real-money casinos in Austria on Casinohex.at is a great opportunity to enjoy all the benefits of playing for real money.