498 lines
11 KiB
INI
498 lines
11 KiB
INI
[Demos]
|
|
Simple expression
|
|
One function
|
|
One function with variable
|
|
Unit and recursion
|
|
OnGetValue Event
|
|
Access to Delphi's objects
|
|
Exception handling
|
|
Working with sets
|
|
Handing Delphi events
|
|
Records
|
|
Calling external functions
|
|
Ole automation
|
|
JvInterpreter Adapters
|
|
How to import Delphi units
|
|
Arrays
|
|
Running delphi forms
|
|
Running delphi reports
|
|
Running delphi units
|
|
List of supported statements
|
|
Credits
|
|
Our plans
|
|
[]
|
|
|
|
[Simple expression\Description]
|
|
This is simple expression.
|
|
JvInterpreterProgram component automatically
|
|
detects 3 types of sources:
|
|
1) simple expression;
|
|
2) one function;
|
|
3) unit;
|
|
|
|
Press 'Run' button, please.
|
|
Button 'Compile' requires unit as source,
|
|
so it doesn't work with this sample.
|
|
|
|
See next example...
|
|
|
|
[Simple expression\Source]
|
|
2*2+(122.34-54.67)*123.5
|
|
|
|
[One function\Description]
|
|
This is one function.
|
|
JvInterpreter detects it by first word;
|
|
it have to be 'begin' or 'var'.
|
|
|
|
[One function\Source]
|
|
begin
|
|
Result := '2*2+(122.34-54.67)*123.5=' +
|
|
IntToStr(2*2+(122.34-54.67)*123.5);
|
|
end;
|
|
|
|
[One function with variable\Description]
|
|
This is one function with var-statement.
|
|
JvInterpreter detects function by first word;
|
|
it have to be 'begin' or 'var'.
|
|
|
|
[One function with variable\Source]
|
|
var
|
|
Variable : real {type ignored} ;
|
|
begin
|
|
Variable := 2*2+(122.34-54.67)*123.5;
|
|
Result := '2*2+(122.34-54.67)*123.5=' + IntToStr(Variable);
|
|
end;
|
|
|
|
[Unit and recursion\Description]
|
|
This example shows structure of JvInterpreter unit.
|
|
It is similar to delphi's unit, but 'interface'
|
|
and 'implementation' keywords are not required
|
|
(more over, they are raise an error).
|
|
|
|
[Unit and recursion\Source]
|
|
unit MyUnit;
|
|
|
|
function main: string;
|
|
var
|
|
IntVariable : integer;
|
|
begin
|
|
IntVariable := 5;
|
|
Result := 'Factorial(5)=' +
|
|
IntToStr(Factorial(IntVariable));
|
|
end;
|
|
|
|
function Factorial(F : integer) : integer;
|
|
begin
|
|
if F <= 1 then
|
|
Result := F
|
|
else
|
|
Result := F * Factorial(F-1);
|
|
end;
|
|
|
|
end.
|
|
|
|
[OnGetValue Event\Description]
|
|
Function MyFunction is calculated in OnGetValue - event.
|
|
It simply adds 1 to passed value.
|
|
|
|
[OnGetValue Event\Source]
|
|
MyFunction(10000)
|
|
|
|
[Access to Delphi's objects\Description]
|
|
This example demonstrates:
|
|
- assigning delphi object to JvInterpreter variable;
|
|
- calling method from object;
|
|
- creating new object through to
|
|
class function Create;
|
|
- calling function with var parameter
|
|
(TStringList.Find);
|
|
- if/then/else statement;
|
|
- try/finally statement;
|
|
|
|
[Access to Delphi's objects\Source]
|
|
var
|
|
v : TObject;
|
|
B : TStringList;
|
|
L : integer;
|
|
r : boolean;
|
|
begin
|
|
V := Application.FindComponent('Test').
|
|
FindComponent('Memo2').Lines;
|
|
B := TStringList.Create;
|
|
try
|
|
B.Assign(V);
|
|
B.Add('MyLine');
|
|
r := B.Find('MyLine', L);
|
|
if r then
|
|
Result := 'found line at position ' +
|
|
IntToStr(L)
|
|
else
|
|
Result := 'not found';
|
|
finally
|
|
B.Free;
|
|
end;
|
|
end;
|
|
|
|
[Exception handling\Description]
|
|
JvInterpreter understands try/finally and
|
|
try/except statements.
|
|
Exceptions in JvInterpreter is native Delphi
|
|
exceptions. It means that exceptions
|
|
raised in JvInterpreter may be handled in
|
|
Delphi and exceptions, raised in
|
|
Delphi functions called from JvInterpreter
|
|
source may be handled in JvInterpreter source.
|
|
To raise exception use standard
|
|
Delphi directive: raise <Object>.
|
|
|
|
Note: to raise exceptions you need
|
|
create instance of object. It means,
|
|
that this object must be registered
|
|
in JvInterpreter adapter.
|
|
|
|
See next examples.
|
|
|
|
[Exception handling\Source]
|
|
var
|
|
v, B : Variant;
|
|
begin
|
|
B := 'ok';
|
|
try
|
|
// raise Exception.Create('Self generated error');
|
|
V := 1 div 0;
|
|
V := V + 1;
|
|
except
|
|
on E: EOverflow do
|
|
B : = 'EOverflow: ' + E.Message;
|
|
on EIntOverflow do
|
|
B : = 'EIntOverflow: ' + E.Message;
|
|
on E: EZeroDivide do
|
|
B : = 'EZeroDivide: ' + E.Message;
|
|
else
|
|
raise
|
|
end;
|
|
Result := ': ' + B;
|
|
end;
|
|
|
|
[Handing Delphi events]
|
|
Page=Event
|
|
[Handing Delphi events\Description]
|
|
In JvInterpreter source you can handle
|
|
delphi events with standard delphi
|
|
manner.
|
|
|
|
Note: to handle events event type
|
|
must be registered in JvInterpreter Adapter.
|
|
|
|
Now click 'Run', then click 'Button4'.
|
|
|
|
[Handing Delphi events\Source]
|
|
unit Unit1;
|
|
|
|
procedure ButtonClick(Sender: TObject);
|
|
begin
|
|
MessageBox(0, TButton(Sender).Caption + ' clicked!', 'Information', MB_ICONINFORMATION);
|
|
end;
|
|
|
|
procedure main;
|
|
var
|
|
v, B : Variant;
|
|
L : integer;
|
|
r : boolean;
|
|
begin
|
|
V := Test.FindComponent('Button4');
|
|
TButton(V).OnClick := ButtonClick;
|
|
end;
|
|
|
|
end.
|
|
|
|
[Working with sets\Description]
|
|
JvInterpreter allows you to work with native
|
|
delphi sets, but only sets with
|
|
up to 32 elements are allowed.
|
|
|
|
Note: you can't work with charset,
|
|
because it contains more than 32 elements.
|
|
Sorry.
|
|
|
|
[Working with sets\Source]
|
|
var
|
|
v : Variant;
|
|
S : string;
|
|
St: Variant;
|
|
begin
|
|
V := Test.FindComponent('Button1');
|
|
St := V.Font.Style;
|
|
S := V.Caption;
|
|
try
|
|
V.Font.Style := V.Font.Style + [fsBold, fsItalic];
|
|
V.Caption := 'Hello';
|
|
MessageBox(0, 'Hello', 'Information', MB_ICONINFORMATION);
|
|
finally
|
|
V.Caption := S;
|
|
V.Font.Style := St;
|
|
end;
|
|
end;
|
|
|
|
[Records\Description]
|
|
In JvInterpreter you can work with Delphi
|
|
records. We provide access to
|
|
following record types:
|
|
TPoint, TRect, TSearchRec.
|
|
|
|
You can add other records using
|
|
JvInterpreter Adapters.
|
|
|
|
[Records\Source]
|
|
var
|
|
F : TSearchRec;
|
|
DosError: Integer;
|
|
Strings: TStrings;
|
|
begin
|
|
Strings := Test.FindComponent('Memo2').Lines;
|
|
Strings.Clear;
|
|
DosError := FindFirst('C:\*.*', faAnyFile, F);
|
|
while DosError = 0 do
|
|
begin
|
|
if (F.Attr and faDirectory) = 0 then
|
|
Strings.Add(F.Name)
|
|
else
|
|
Strings.Add('\' + F.Name);
|
|
DosError := FindNext(F);
|
|
end;
|
|
FindClose(F);
|
|
DosError := 0;
|
|
end;
|
|
|
|
[Calling external functions\Description]
|
|
You can declare external function
|
|
in source and then call it.
|
|
|
|
Note: only standard types are allowed;
|
|
var parameters don't allowed.
|
|
|
|
[Calling external functions\Source]
|
|
unit Unit1;
|
|
|
|
function MessageBox(hWnd: integer; lpText, lpCaption: PChar; uType: integer): Integer;
|
|
external 'user32.dll' name 'MessageBoxA';
|
|
|
|
Procedure main;
|
|
begin
|
|
MessageBox(0, 'Hello, World !', 'calling dll', MB_ICONINFORMATION);
|
|
end;
|
|
|
|
end.
|
|
|
|
[Ole automation\Description]
|
|
|
|
[Ole automation\Source]
|
|
var
|
|
MSW: Variant;
|
|
i: Integer;
|
|
begin
|
|
MSW := GetOleObject('Word.Basic');
|
|
MSW.AppShow;
|
|
MSW.FileNew;
|
|
MSW.Insert('JvInterpreter Demo !');
|
|
MSW := 0;
|
|
end;
|
|
|
|
[JvInterpreter Adapters]
|
|
Page=Empty
|
|
[JvInterpreter Adapters\Description]
|
|
All functions, classes, records, ..
|
|
must be registered in JvInterpreter Adapter
|
|
before they can be used in JvInterpreter
|
|
source. Usually you create special
|
|
unit to obtain access to delphi
|
|
functions and objects.
|
|
We call this special units as
|
|
'JvInterpreter Adapters' or 'Adapters'.
|
|
|
|
This version of JVCL Library includes
|
|
Adapters:
|
|
JvInterpreter_System, JvInterpreter_SysUtils,
|
|
JvInterpreter_Windows(only few functions and constants),
|
|
JvInterpreter_Classes, JvInterpreter_Controls,
|
|
JvInterpreter_StdCtrls, JvInterpreter_ExtCtrls,
|
|
JvInterpreter_Forms, JvInterpreter_Dialogs,
|
|
JvInterpreter_Graphics, JvInterpreter_Menus,
|
|
JvInterpreter_Grids, JvInterpreter_Db,
|
|
JvInterpreter_DbTables, JvInterpreter_DBCtrls,
|
|
JvInterpreter_DBGrids, JvInterpreter_Quickrpt;
|
|
|
|
All adapters are based on Delphi 3
|
|
units;
|
|
Compiler {$IF} directives allow
|
|
to compile it in all version.
|
|
|
|
'Quickrpt' unit is very different
|
|
in different Delphi versions.
|
|
JvInterpreter_Quickrpt is based on Delphi3
|
|
and contains code for Delphi2
|
|
and CBuilder1, but this code not
|
|
complete, because we don't have
|
|
QuickReport 1 sources.
|
|
|
|
[How to import Delphi units]
|
|
Page=Empty
|
|
[How to import Delphi units\Description]
|
|
You can create adapter units
|
|
manually, but it is not very
|
|
interesting.
|
|
|
|
Use program Pas2JvInterpreter, placed in
|
|
'RALib\Tools\Pas2JvInterpreter' folder to
|
|
automatically create JvInterpreter Adapters.
|
|
In most cases errors occured when
|
|
you try to compile created unit, so
|
|
you must manually correct it.
|
|
|
|
Take a look at the adapter sources,
|
|
which are included in JVCL Library.
|
|
Those are good examples. All adapters
|
|
illustrate access to Delphi objects.
|
|
JvInterpreter_Windows shows access to
|
|
records and external functions.
|
|
|
|
|
|
[Arrays\Description]
|
|
JvInterpreter supports multidimensional arrays
|
|
as local and global variables. Also
|
|
arrays in indexed properties and in
|
|
open array parameters are supported.
|
|
|
|
Also JvInterpreter supports default indexed
|
|
property of objects.
|
|
For example, you can write
|
|
Memo1.Lines[1] := 'Hello'
|
|
or
|
|
Memo1.Lines.Strings[1] := 'Hello'
|
|
|
|
[Arrays\Source]
|
|
var
|
|
A:Array [1..200] of integer;
|
|
i:Integer;
|
|
begin
|
|
for i := 1 to 200 do
|
|
begin
|
|
A[I] := i*i;
|
|
Result:= A[200];
|
|
end;
|
|
end;
|
|
|
|
|
|
[Running delphi forms]
|
|
Page=ExternalForm
|
|
[Running delphi forms\Description]
|
|
TJvInterpreterFm component can create
|
|
delphi form from dfm-file, and load
|
|
assotiated pas-file.
|
|
Then it can show form, or you can
|
|
call any function from its pas-file.
|
|
|
|
JvInterpreter attempts to load normal Delphi
|
|
pas-file and ignore all interface part.
|
|
|
|
Click 'Run form...' and select
|
|
'Unit1.pas'. Then try to interact
|
|
with form.
|
|
|
|
|
|
[Running delphi reports]
|
|
Page=ExternalReport
|
|
[Running delphi reports\Description]
|
|
This sample is based on previous one
|
|
but loaded form is not shown.
|
|
We attempt to find QuickRep1 (for
|
|
QR2) or QuickReport1 (for QR1)
|
|
component on the form and then
|
|
call its Preview method.
|
|
|
|
Loaded form can contain its own
|
|
data access components or reference
|
|
to components in .exe forms or
|
|
data modules;
|
|
|
|
Click 'Run report...' and select
|
|
'QRUnit_D3_D4_B3.pas' or
|
|
'QRUnit_D2_B1.pas' depending on
|
|
your Delphi versions.
|
|
|
|
[Running delphi units]
|
|
Page=ExternalUnit
|
|
[Running delphi units\Description]
|
|
This is more efficient way
|
|
to work with Delphi forms.
|
|
|
|
Delphi's pas/dfm file can be placed
|
|
in uses clause of JvInterpreter-script.
|
|
This allows to manipulate with
|
|
other form with standard Delphi manner
|
|
|
|
Click 'Run unit...' and select
|
|
'project1\project1.pas'.
|
|
Then try to interact with form.
|
|
|
|
[List of supported statements]
|
|
Page=Empty
|
|
[List of supported statements\Description]
|
|
Now JvInterpreter supports following pascal
|
|
statements:
|
|
- begin/end;
|
|
- var declaration;
|
|
- const declaration;
|
|
- if/then/else;
|
|
- for/do;
|
|
- while/do;
|
|
- repeat/until;
|
|
- break, continue;
|
|
- case;
|
|
- exit;
|
|
- try/finally;
|
|
- try/except/on;
|
|
- raise and raise <object>;
|
|
- assignment;
|
|
- function calls;
|
|
- uses clause;
|
|
|
|
[Credits]
|
|
Page=Empty
|
|
[Credits\Description]
|
|
JvInterpreter is fully writen by us,
|
|
JVCL Library authors.
|
|
|
|
But some good ideas (no line
|
|
of code) was taken from
|
|
'Delphin interpreter' by
|
|
Dream Company:
|
|
www.dreamcompany.com
|
|
|
|
Many guys sent us bug reports and
|
|
fixes.
|
|
Andrej Olejnik has coded initial
|
|
array support in JvInterpreter.
|
|
|
|
[Credits\Source]
|
|
=>
|
|
[Our plans]
|
|
Page=Empty
|
|
[Our plans\Description]
|
|
Like all great product :) JvInterpreter
|
|
is allways in development.
|
|
Now it contains most of things
|
|
we are need to.
|
|
And all that we do now are
|
|
we correct bugs.
|
|
|
|
We very need you comments.
|
|
If you found JvInterpreter interesting
|
|
or have found any bug
|
|
please mail to us:
|
|
|
|
black@infa.ru.
|
|
|
|
[Our plans\Source]
|
|
=>
|