The last topic we discuss is how to pass computational data from the plugin function to the update function. Two methods are quite inelegant: it is possible to write a file, or to pass data on the stack.
The best solution, however, is to use the my pointer in TStack to create a struct containing data of interest for the update function.
Assume, we want to pass a list of points. First, one should define a data structure to be passed:
type TMyData = record
xP : Array[1..MAX_POINTS] of Real;
yP : Array[1..MAX_POINTS] of Real;
end;
In the plugin method, at the beginning of the computation, we reserve memory for this structure, then we store the pointer in my and initialize it.
if stk.Progress = 0 then
begin
GetMem(Stk.My, SizeOf(TMyData));
with TMyData(Stk.My^) do
begin
for i:=1 to MAX_POINTS do
begin
xP[i]:=0;
yP[i]:=0;
end;
end; {with}
end;
In the update function, we free the reserved memory at the end of the computation with
if Stk.Progress = 100 then FreeMem(Stk.My, SizeOf(TMyData));
To access the first element of the xP array in both function and update method we typecast the my pointer to the TMyData structure before accessing the field xP:
TMyData(Stk.My^).xP[1];