Back in January I had asked for some advice for
how to implement a feature from a very old project with Scripter in a
modern version of the program. See, Creating a new type of Procedure I
understand that trying to change scripter's Pascal language to include
something like that would be a very daunting task for even the best of
programmers. Especially since there is not much in the way of
documentation, or comments, on how to create your own custom language
for scripter. And the advice to create a separate form that the user
would use to define such "events" and to execute them is no practical.
Nor is it feasible to do so.
As a reminder to the original post, the special Procedures are:
// This procedure would run when the amount of time since
// the last time it waS run has has been reached or past.
procedure myProcedure EVERY <time>
// This procedure would run only when the condition is met.
procedure myProcedure2 WHEN <condition (as in a IF statement)>
// This procedure would only run when the event has happened
procedure myProcedure3 ON <event>
three procedures would not be run, even if the conditions for them has
been met. Unless the ProcessMessages method/command is used in a
procedure/function. Thus making the procedure run pretty much any time
the the PrecessMessages is called.
method/command would examine the defined procedures and decide if their
conditions/events has transpired and run the the procedure if required.
In my work, I have come up with this approach to the problem:
1. Have the user create the procedure they wish to use for the "event."
Have the user use the method SetEvent to define an event,
it's condition, and the procedure to be run when the condition has been met.
Then user uses the ProcessMessages, like in the old program, to allow
the procedures to run if their event conditions have been met.
So, this is what I have:
Custom Event class: TEvent
TACToolEvent = Class(TComponent)
EventType, CmdEvent, Condition: String;
ParamCount, iTimes: Integer;
Index, NextCheck: DWord;
the user creates and "event" in the script. The CreateEvent method
creates on event object and stores it in a TStringList lstEvents.
when the user calls the ProcessMessages method in any
procedure/function. The ProcessMessages first checks to see if any
events have been defined, lstEvents.Count > 0.
If there are events
defined, then it iterates through the list and check each Event object
to see if it's conditions has been met. And then runs the procedure tied
to the "event."
At this time I have the Every event coded and it works fine. But, my problem is the other two. The WHEN and ON events.
it would be easier if I could somehow to convert the WHEN event
condition to an IF statement and have Scripter handle it. There is not
much in the way of comments to help me to do this. So, I would have to
create a custom procedure to handle the if logic. But, the problem is
that the condition could use any global/local variables/constants the
user creates. As well as any custom Constants build into the Custom AP.
Example of the SetEvent for the WHEN event:
SetEvent('MyTestProcedure1', 'WHEN', 'i := 300');
ON event strictly uses custom Boolean Constants defined in the AP that
shows when a "Event" defined by the program/plugin has happen. A good
example of this is the EOF and BOF used to check to see if we have
reached the end, or beginning, of a file.
So, how would I go
about accessing the variables/constants, and the AP Constants, value(s)
for use in checking the event's condition?