Insert & Retrieve Data (Column Names Only)
Data1, Data2, Data3 etc are pre-declared within a Map, but must be explicitly declared within a Custom Script.
Data1, Data2, Data3 etc are pre-initialised within a Map, but must be explicitly initialised within a Custom Script.
Data1, Data2, Data3 etc are cleaned up automatically by a Map, but must be explicitly removed for Custom Script.
procedure
ScriptEvent (
var
Value : variant);
var
Data1: TFloClientDataSet;
//declare
begin
Data1 := TFloClientDataSet
.
Create(
nil
);
//initialise
// define the column structure of the dataset ...
// create the dataset, with columns named 'ID' and 'Name'
GetCustomDataSet(Data1,[
'ID'
,
'Name'
]);
// add some data into the custom dataset ...
Data1
.
Insert;
// insert a new row into the dataset
Data1[
'ID'
].Value :=
'1'
;
// set the value of the ID field
Data1[
'Name'
].Value :=
'Betty'
;
// set the value of the Name field
Data1
.
Post;
// save the changes to this row
Data1
.
Insert;
// insert another new row into the dataset
Data1[
'ID'
].Value :=
'2'
;
Data1[
'Name'
].Value :=
'Nigel'
;
Data1
.
Post;
Data1
.
Insert;
// insert another new row into the dataset
Data1[
'ID'
].Value :=
'10'
;
Data1[
'Name'
].Value :=
'Roger'
;
Data1
.
Post;
{ OPTIONAL: sort the dataset (on the ID column) ...
NOTE: custom dataset columns are string(255) by default,
so the sort returns '1', '10', '2' }
Data1
.
IndexFieldNames :=
'ID'
;
// retrieve data from the custom dataset ...
Data1
.
First;
while
(
not
Data1
.
EOF)
do
begin
// read values from the dataset until EOF Reached
LogInfo(
'ID:'
+ Data1[
'ID'
].AsString +
';Name:'
+ Data1[
'Name'
].AsString);
Data1
.
Next;
end
;
if
(Assigned(Data1))
then
Data1
.
Free;
end
;