You've already forked lazarus-ccr
jvcllaz: Add TJvInterpreter units in JvPascalInterpreter package, including two demos.
Change MIME type of all package files to text/xml. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7246 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="JvInterpreterCallFunction"/>
|
||||
<Scaled Value="True"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<XPManifest>
|
||||
<DpiAware Value="True"/>
|
||||
</XPManifest>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="SynEdit"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="JvPascalInterpreterR"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="JvInterpreterCallFunction.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="JvInterpreterCallFunctionFm.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="..\..\..\bin\$(TargetCPU)-$(TargetOS)\JvInterpreterCallFunction"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,14 @@
|
||||
program JvInterpreterCallFunction;
|
||||
|
||||
uses
|
||||
Interfaces, Forms,
|
||||
JvInterpreterCallFunctionFm in 'JvInterpreterCallFunctionFm.pas' {Form1};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Scaled:=True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
@ -0,0 +1,192 @@
|
||||
object Form1: TForm1
|
||||
Left = 450
|
||||
Height = 690
|
||||
Top = 165
|
||||
Width = 965
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 690
|
||||
ClientWidth = 965
|
||||
Color = clBtnFace
|
||||
Font.Color = clWindowText
|
||||
OnShow = FormShow
|
||||
LCLVersion = '2.1.0.0'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Button2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Edit1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 456
|
||||
Height = 15
|
||||
Top = 13
|
||||
Width = 35
|
||||
BorderSpacing.Left = 200
|
||||
Caption = 'Result:'
|
||||
ParentColor = False
|
||||
end
|
||||
inline JvHLEditor1: TSynEdit
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Button2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 637
|
||||
Top = 41
|
||||
Width = 941
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 12
|
||||
BorderSpacing.Bottom = 12
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Font.Height = -13
|
||||
Font.Name = 'Courier New'
|
||||
Font.Pitch = fpFixed
|
||||
Font.Quality = fqCleartype
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
TabOrder = 0
|
||||
Gutter.Width = 57
|
||||
Gutter.MouseActions = <>
|
||||
RightGutter.Width = 0
|
||||
RightGutter.MouseActions = <>
|
||||
Highlighter = SynPasSyn1
|
||||
Keystrokes = <>
|
||||
MouseActions = <>
|
||||
MouseTextActions = <>
|
||||
MouseSelActions = <>
|
||||
Lines.Strings = (
|
||||
'unit UserFunctions;'
|
||||
''
|
||||
'// sample of a user-created-library of jvinterpreter functions that your compiled'
|
||||
'// program might access:'
|
||||
''
|
||||
''
|
||||
'// notice that there is no interface/implementation section in this '
|
||||
'// interpreter-only unit.'
|
||||
''
|
||||
'function MyFunction(B:String):Integer;'
|
||||
'begin'
|
||||
' result := Length(B);'
|
||||
'end;'
|
||||
''
|
||||
'function MyFunction2(A,B:Integer):Integer;'
|
||||
'begin'
|
||||
' result := A+B;'
|
||||
'end;'
|
||||
''
|
||||
''
|
||||
'end.'
|
||||
)
|
||||
VisibleSpecialChars = [vscSpace, vscTabAtLast]
|
||||
SelectedColor.BackPriority = 50
|
||||
SelectedColor.ForePriority = 50
|
||||
SelectedColor.FramePriority = 50
|
||||
SelectedColor.BoldPriority = 50
|
||||
SelectedColor.ItalicPriority = 50
|
||||
SelectedColor.UnderlinePriority = 50
|
||||
SelectedColor.StrikeOutPriority = 50
|
||||
BracketHighlightStyle = sbhsBoth
|
||||
BracketMatchColor.Background = clNone
|
||||
BracketMatchColor.Foreground = clNone
|
||||
BracketMatchColor.Style = [fsBold]
|
||||
FoldedCodeColor.Background = clNone
|
||||
FoldedCodeColor.Foreground = clGray
|
||||
FoldedCodeColor.FrameColor = clGray
|
||||
MouseLinkColor.Background = clNone
|
||||
MouseLinkColor.Foreground = clBlue
|
||||
LineHighlightColor.Background = clNone
|
||||
LineHighlightColor.Foreground = clNone
|
||||
inline SynLeftGutterPartList1: TSynGutterPartList
|
||||
object SynGutterMarks1: TSynGutterMarks
|
||||
Width = 24
|
||||
MouseActions = <>
|
||||
end
|
||||
object SynGutterLineNumber1: TSynGutterLineNumber
|
||||
Width = 17
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clBtnFace
|
||||
MarkupInfo.Foreground = clNone
|
||||
DigitCount = 2
|
||||
ShowOnlyLineNumbersMultiplesOf = 1
|
||||
ZeroStart = False
|
||||
LeadingZeros = False
|
||||
end
|
||||
object SynGutterChanges1: TSynGutterChanges
|
||||
Width = 4
|
||||
MouseActions = <>
|
||||
ModifiedColor = 59900
|
||||
SavedColor = clGreen
|
||||
end
|
||||
object SynGutterSeparator1: TSynGutterSeparator
|
||||
Width = 2
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clWhite
|
||||
MarkupInfo.Foreground = clGray
|
||||
end
|
||||
object SynGutterCodeFolding1: TSynGutterCodeFolding
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clNone
|
||||
MarkupInfo.Foreground = clGray
|
||||
MouseActionsExpanded = <>
|
||||
MouseActionsCollapsed = <>
|
||||
end
|
||||
end
|
||||
end
|
||||
object Button1: TButton
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 12
|
||||
Height = 25
|
||||
Top = 8
|
||||
Width = 113
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 8
|
||||
Caption = 'Call MyFunction'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 1
|
||||
end
|
||||
object Button2: TButton
|
||||
AnchorSideLeft.Control = Button1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Button1
|
||||
Left = 137
|
||||
Height = 25
|
||||
Top = 8
|
||||
Width = 119
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
Caption = 'Call MyFunction2'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 2
|
||||
end
|
||||
object Edit1: TEdit
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Button1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 503
|
||||
Height = 23
|
||||
Top = 9
|
||||
Width = 121
|
||||
BorderSpacing.Left = 12
|
||||
ReadOnly = True
|
||||
TabOrder = 3
|
||||
end
|
||||
object JvInterpreterProgram1: TJvInterpreterProgram
|
||||
OnGetValue = JvInterpreterProgram1GetValue
|
||||
left = 328
|
||||
top = 96
|
||||
end
|
||||
object SynPasSyn1: TSynPasSyn
|
||||
Enabled = False
|
||||
CommentAttri.Foreground = clTeal
|
||||
CompilerMode = pcmDelphi
|
||||
NestedComments = False
|
||||
TypeHelpers = True
|
||||
left = 325
|
||||
top = 272
|
||||
end
|
||||
end
|
@ -0,0 +1,103 @@
|
||||
unit JvInterpreterCallFunctionFm;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
StdCtrls, Dialogs, SynEdit, SynHighlighterPas, //JvComponentBase,
|
||||
JvInterpreter, JvExControls;
|
||||
// JvEditorCommon, JvEditor, JvHLEditor;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
JvHLEditor1: TSynEdit; //JvHLEditor;
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Edit1: TEdit;
|
||||
Label1: TLabel;
|
||||
JvInterpreterProgram1: TJvInterpreterProgram;
|
||||
SynPasSyn1: TSynPasSyn;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure JvInterpreterProgram1GetValue(Sender: TObject;
|
||||
Identifier: String; var Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
var
|
||||
Args:TJvInterpreterArgs;
|
||||
begin
|
||||
{ before we get here, JvInterpreterProgram1.Pas is already set to show the text in the HLEditor. }
|
||||
Assert(JvInterpreterProgram1.Pas.Count>0);
|
||||
|
||||
|
||||
{ THIS IS ONLY ONE POSSIBLE WAY TO CALL CallFunction! Look at both ways please. }
|
||||
|
||||
{Args is a temporary argument data holder object}
|
||||
Args := TJvInterpreterArgs.Create;
|
||||
try
|
||||
Args.Count := 1;
|
||||
Args.Values[0] := 'SomeText';
|
||||
JvInterpreterProgram1.CallFunction( 'MyFunction', Args, []);
|
||||
{ show result to user:}
|
||||
Edit1.Text := VarToStr( JvInterpreterProgram1.VResult );
|
||||
finally
|
||||
Args.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormShow(Sender: TObject);
|
||||
begin
|
||||
{ move program text over to interpreter! }
|
||||
JvInterpreterProgram1.Pas.Assign( JvHLEditor1.Lines );
|
||||
end;
|
||||
|
||||
procedure TForm1.JvInterpreterProgram1GetValue(Sender: TObject;
|
||||
Identifier: String; var Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
begin
|
||||
Identifier := UpperCase(Identifier);
|
||||
|
||||
if (Identifier='LENGTH') and (ARgs.Count=1) and (VarIsStr(Args.Values[0])) then
|
||||
begin
|
||||
Value := Length(ARgs.Values[0]);
|
||||
Done := true;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
var
|
||||
Param1,Param2,Param3:Variant;
|
||||
begin
|
||||
{ before we get here, JvInterpreterProgram1.Pas is already set to show the text in the HLEditor. }
|
||||
Assert(JvInterpreterProgram1.Pas.Count>0);
|
||||
|
||||
{ Alternative method without creating/freeing JvInterpreter args is to use Params instead, but not Args:}
|
||||
|
||||
Param1 := 10;
|
||||
Param2 := 20;
|
||||
JvInterpreterProgram1.CallFunction( 'MyFunction2', nil, [Param1,Param2] );
|
||||
|
||||
|
||||
{ show result to user:}
|
||||
Edit1.Text := VarToStr( JvInterpreterProgram1.VResult );
|
||||
end;
|
||||
|
||||
|
||||
end.
|
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="JvInterpreterSimpleExpression"/>
|
||||
<Scaled Value="True"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<XPManifest>
|
||||
<DpiAware Value="True"/>
|
||||
</XPManifest>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="JvCustomLazR"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="JvPascalInterpreterR"/>
|
||||
<MaxVersion Major="1" Release="6"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="JvInterpreterSimpleExpression.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="JvInterpreterSimpleExpressionFm.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="..\..\..\bin\$(TargetCPU)-$(TargetOS)\JvInterpreterSimpleExpression"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,16 @@
|
||||
program JvInterpreterSimpleExpression;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Interfaces, Forms,
|
||||
JvInterpreterSimpleExpressionFm in 'JvInterpreterSimpleExpressionFm.pas' {Form1};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Scaled := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
@ -0,0 +1,184 @@
|
||||
object Form1: TForm1
|
||||
Left = 192
|
||||
Height = 177
|
||||
Top = 66
|
||||
Width = 397
|
||||
AutoSize = True
|
||||
Caption = 'Simple Expressions in JvInterpreter'
|
||||
ClientHeight = 177
|
||||
ClientWidth = 397
|
||||
Color = clBtnFace
|
||||
Font.Color = clWindowText
|
||||
LCLVersion = '2.1.0.0'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Edit1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 12
|
||||
Height = 15
|
||||
Top = 10
|
||||
Width = 56
|
||||
BorderSpacing.Left = 12
|
||||
Caption = 'Expression'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = Edit2
|
||||
AnchorSideTop.Control = EditA
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 76
|
||||
Height = 15
|
||||
Top = 64
|
||||
Width = 8
|
||||
Caption = 'A'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label3: TLabel
|
||||
AnchorSideLeft.Control = Label2
|
||||
AnchorSideTop.Control = EditB
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 76
|
||||
Height = 15
|
||||
Top = 89
|
||||
Width = 7
|
||||
Caption = 'B'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label4: TLabel
|
||||
AnchorSideLeft.Control = Label2
|
||||
AnchorSideTop.Control = EditC
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 76
|
||||
Height = 15
|
||||
Top = 114
|
||||
Width = 8
|
||||
Caption = 'C'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label5: TLabel
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideTop.Control = Edit2
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 12
|
||||
Height = 15
|
||||
Top = 34
|
||||
Width = 32
|
||||
Caption = 'Result'
|
||||
ParentColor = False
|
||||
end
|
||||
object Button1: TButton
|
||||
AnchorSideLeft.Control = Edit1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Edit1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 241
|
||||
Height = 25
|
||||
Top = 5
|
||||
Width = 129
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Right = 12
|
||||
Caption = 'Evaluate Expression'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 0
|
||||
end
|
||||
object Edit1: TEdit
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 76
|
||||
Height = 22
|
||||
Top = 6
|
||||
Width = 153
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 6
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Courier New'
|
||||
ParentFont = False
|
||||
TabOrder = 1
|
||||
Text = 'A + MAX(B,C)'
|
||||
end
|
||||
object EditA: TJvValidateEdit
|
||||
AnchorSideLeft.Control = Label2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Edit2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 96
|
||||
Height = 23
|
||||
Top = 60
|
||||
Width = 73
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 8
|
||||
CriticalPoints.MaxValue = 0
|
||||
CriticalPoints.MinValue = 0
|
||||
CriticalPoints.MaxValueIncluded = False
|
||||
CriticalPoints.MinValueIncluded = False
|
||||
EditText = '100'
|
||||
MaxValue = 0
|
||||
MinValue = 0
|
||||
TabOrder = 2
|
||||
end
|
||||
object EditB: TJvValidateEdit
|
||||
AnchorSideLeft.Control = EditA
|
||||
AnchorSideTop.Control = EditA
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 96
|
||||
Height = 23
|
||||
Top = 85
|
||||
Width = 73
|
||||
BorderSpacing.Top = 2
|
||||
CriticalPoints.MaxValue = 0
|
||||
CriticalPoints.MinValue = 0
|
||||
CriticalPoints.MaxValueIncluded = False
|
||||
CriticalPoints.MinValueIncluded = False
|
||||
EditText = '50'
|
||||
MaxValue = 0
|
||||
MinValue = 0
|
||||
TabOrder = 3
|
||||
end
|
||||
object EditC: TJvValidateEdit
|
||||
AnchorSideLeft.Control = EditA
|
||||
AnchorSideTop.Control = EditB
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 96
|
||||
Height = 23
|
||||
Top = 110
|
||||
Width = 73
|
||||
BorderSpacing.Top = 2
|
||||
BorderSpacing.Bottom = 12
|
||||
CriticalPoints.MaxValue = 0
|
||||
CriticalPoints.MinValue = 0
|
||||
CriticalPoints.MaxValueIncluded = False
|
||||
CriticalPoints.MinValueIncluded = False
|
||||
EditText = '60'
|
||||
MaxValue = 0
|
||||
MinValue = 0
|
||||
TabOrder = 4
|
||||
end
|
||||
object Edit2: TEdit
|
||||
AnchorSideLeft.Control = Edit1
|
||||
AnchorSideTop.Control = Edit1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Edit1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 76
|
||||
Height = 22
|
||||
Top = 30
|
||||
Width = 153
|
||||
BorderSpacing.Top = 2
|
||||
Color = clBtnFace
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Courier New'
|
||||
ParentFont = False
|
||||
ReadOnly = True
|
||||
TabOrder = 5
|
||||
end
|
||||
object JvInterpreterProgram1: TJvInterpreterProgram
|
||||
OnGetValue = JvInterpreterProgram1GetValue
|
||||
OnSetValue = JvInterpreterProgram1SetValue
|
||||
left = 280
|
||||
top = 80
|
||||
end
|
||||
end
|
@ -0,0 +1,135 @@
|
||||
unit JvInterpreterSimpleExpressionFm;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, StdCtrls, JvValidateEdit, JvInterpreter;
|
||||
|
||||
type
|
||||
TForm1 = class(TForm)
|
||||
JvInterpreterProgram1: TJvInterpreterProgram;
|
||||
Button1: TButton;
|
||||
Label1: TLabel;
|
||||
Edit1: TEdit;
|
||||
Label2: TLabel;
|
||||
EditA: TJvValidateEdit;
|
||||
EditB: TJvValidateEdit;
|
||||
Label3: TLabel;
|
||||
EditC: TJvValidateEdit;
|
||||
Label4: TLabel;
|
||||
Label5: TLabel;
|
||||
Edit2: TEdit;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure JvInterpreterProgram1GetValue(Sender: TObject;
|
||||
Identifier: String; var Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
procedure JvInterpreterProgram1SetValue(Sender: TObject;
|
||||
Identifier: String; const Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
private
|
||||
{ Private declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
Math;
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
begin
|
||||
{ BEGIN
|
||||
RESULT := <EXPRESSION>;
|
||||
END
|
||||
|
||||
Note: Any time a variable or function name is invoked, the GetValue event is fired....
|
||||
}
|
||||
JvInterpreterProgram1.Source := 'begin'+Chr(13)+
|
||||
'result := '+ Edit1.Text+';'+Chr(13)+
|
||||
'end;';
|
||||
JvInterpreterProgram1.Run;
|
||||
|
||||
Edit2.Text := VarToStr( JvInterpreterProgram1.VResult);
|
||||
end;
|
||||
|
||||
procedure TForm1.JvInterpreterProgram1GetValue(Sender: TObject;
|
||||
Identifier: String; var Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
begin
|
||||
Identifier := UpperCase(Identifier);
|
||||
{ This event is fired by JvInterpreter not only to get variable names (A=5)
|
||||
but also to evaluate expressions like Foo(3), where Foo might be a function
|
||||
defined by you, with parameters. Args contains those parameters. }
|
||||
|
||||
{ you would not typically do a brute-force block of if-else statements here in a
|
||||
real program, but would do some kind of more elegant lookup in a table of your
|
||||
own named data objects that are used for your logic, to look up variables
|
||||
and function names. }
|
||||
if Identifier='A' then
|
||||
begin
|
||||
Value := EditA.Value;
|
||||
Done := true; {VERY IMPORTANT!}
|
||||
end
|
||||
else
|
||||
if Identifier='B' then
|
||||
begin
|
||||
Value := EditB.Value;
|
||||
Done := true; {VERY IMPORTANT!}
|
||||
end
|
||||
else
|
||||
if Identifier='C' then
|
||||
begin
|
||||
Value := EditC.Value;
|
||||
Done := true; {VERY IMPORTANT!}
|
||||
end
|
||||
else { FUNCTION DEMO! }
|
||||
if (Identifier='MAX') then begin
|
||||
if (Args.Count=2) and
|
||||
VarIsNumeric(Args.Values[0]) and
|
||||
VarIsNumeric(Args.Values[1])
|
||||
then begin
|
||||
Value := Max(double(Args.Values[0]), double(Args.Values[1]));
|
||||
Done := true; {VERY IMPORTANT!}
|
||||
end else begin
|
||||
{ You can raise exceptions if invalid parameters are provided, or just let the default
|
||||
'not found' error get raised.}
|
||||
JvInterpreterError(ieIncompatibleTypes,0); // or ieNotEnoughParams, or others.
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TForm1.JvInterpreterProgram1SetValue(Sender: TObject;
|
||||
Identifier: String; const Value: Variant; Args: TJvInterpreterArgs;
|
||||
var Done: Boolean);
|
||||
begin
|
||||
if VarIsNumeric(Value) then begin
|
||||
if Identifier='A' then
|
||||
begin
|
||||
EditA.Value := Value;
|
||||
Done := true;
|
||||
end
|
||||
else
|
||||
if Identifier='B' then
|
||||
begin
|
||||
EditB.Value := Value;
|
||||
Done := true;
|
||||
end
|
||||
else if Identifier='C' then
|
||||
begin
|
||||
EditC.Value := Value;
|
||||
Done := true;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user