home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 February
/
Chip_2000-02_cd.bin
/
zkuste
/
Delphi
/
navody
/
tt
/
objvm.exe
/
SAMPLE
/
Unit1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-07-02
|
4KB
|
150 lines
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
LangValMessages,CompEd, StdCtrls, Compiler, RXSplit, Grids, Outline,
ExtCtrls,CmpUtils,ObjLangF, Code, SpeedBar, Buttons,Decompiler,ShowProc,
uObjVM, ObjVM, LangValue, VisualValue, LangProc, ProxyValue;
type
TForm1 = class(TForm)
Panel1: TPanel;
CompileBut: TButton;
Memo1: TMemo;
RxSplitter1: TRxSplitter;
aCode: TCode;
SpeedBar1: TSpeedBar;
SpeedbarSection1: TSpeedbarSection;
BitBtn1: TBitBtn;
Memo2: TMemo;
BitBtn2: TBitBtn;
LangProc1: TLangProc;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure CompileButClick(Sender: TObject);
procedure Compiler1Error(Sender: TObject; LineNo, TokenNo,
ErrorType: Integer; const Token, Msg: string);
procedure Compiler1TreeReady(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure LangProc1Exec(Sender: TVisualValue; S: IValStack;
MustReturn: Boolean);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses InputQueryProc,VarLangValue, uRunTime;
{$R *.DFM}
procedure TForm1.CompileButClick(Sender: TObject);
begin
if ObjLang.CompileTo(Memo1.Lines,aCode)
then
Caption:='Ok'
else
Caption:='Error';
end;
procedure TForm1.Compiler1Error(Sender: TObject; LineNo, TokenNo,
ErrorType: Integer; const Token, Msg: string);
begin
MessageDlg(Format('Error %s %s',[Token,Msg]),mtInformation,[mbOk],0)
end;
procedure TForm1.Compiler1TreeReady(Sender: TObject);
begin
// TreeToOutline(Compiler1.Tree,Outline1);
end;
procedure TForm1.Panel1Click(Sender: TObject);
begin
// EditCompiler(Compiler1,nil);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
With TObjLang.Create(nil) do // Create new instance of language
begin
try
try
CompileTo(Memo1.Lines,aCode); // Compile contents of Memo1.Lines to aCode
Caption:='Ok'; // if no exceptions then Caption = Ok
Decompile(aCode,Memo2.Lines); // Memo2 is filled with string representation
// of aCode
except
On e:ECompilerError do // If any language error
begin
MessageDlg('Line:'+IntToStr(e.LineNo)+' Token:'+IntToStr(e.TokenNo)+': "'
+e.Token+'" Error: "'+e.Message+'"',mtError,[mbOk],0);
Form1.Caption:=e.Message;
end;
On e:Exception do // If other errors
begin
Form1.Caption:=e.Message;
end;
end;
finally Free end;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
RunTime.VM.Run(aCode);
end;
procedure TForm1.LangProc1Exec(Sender: TVisualValue; S: IValStack;
MustReturn: Boolean);
// S is a stack with input parameters
// MustReturn shows if procedure must return a value
// (used as a function)
Var I:Integer;
str:string; // str - string to set to caption
Res:TVarLangValue; // Result of call
begin
str:='';
for i:=0 to S.FrameCount-1 do // For all input parameters do
begin
str:=str+s.FrameValues[i].AsString;// concatenate all parameters tp
// str
end;
if s.FrameCount<>0 then Caption:=str; // If any parameter given - set it to caption
S.DropFrame; // Drop input frame of stack
if MustReturn then // If we must return a result
begin
Res:=TVarLangValue.Create(nil); // Create new variant value
Res.AsString:=Caption; // Set it from caption
S.Push(Res); // Push it to data stack
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.Filename);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Memo1.Lines.SaveTofile(SaveDialog1.Filename);
end;
end;
end.