home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 February
/
Chip_2000-02_cd.bin
/
zkuste
/
Delphi
/
navody
/
tt
/
objvm.exe
/
UNITS
/
LangValue.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-06-27
|
6KB
|
152 lines
{contains TLangValue - Value for macro language}
unit LangValue;
interface
uses
LangValMessages,Classes;
type ILangValue=class;
{IValueOwner is interface of something that can contain ILangValue }
IValueOwner=class(TComponent)
public
procedure AddValue(const s:string;Value:ILangValue);virtual;abstract;
procedure RemoveValue(Value:ILangValue);virtual;abstract;
end;
{IValStack is an interface to stack of ILangValue. Implementaton }
{see in ValStack unit }
IValStack=class
protected
function rdFrameValues(No:integer):ILangValue;virtual;abstract;
public
{Pops a value from top of stack}
function Pop:ILangValue;virtual;abstract;
{Pushes a value to stack}
procedure Push(a:ILangValue);virtual;abstract;
{Removes a procedure call frame from top of stack}
procedure DropFrame;virtual;abstract;
{Provides access to topmost frame values}
property FrameValues[No:Integer]:ILangValue read rdFrameValues;
{Counts values in frame}
function FrameCount:integer;virtual;abstract;
end;
{ILangValue is a class providing all language objects functionality. }
{Variables,Values,Procedures,Objects are implementation of ILangValue.}
{}
ILangValue=class(IValueOwner)
protected
function rdAsString:string;virtual;
procedure wrAsString(a:string);virtual;
function rdAsInteger:integer;virtual;
procedure wrAsInteger(a:integer);virtual;
function rdAsBoolean:boolean;virtual;
procedure wrAsBoolean(a:boolean);virtual;
function rdAsVariant:variant;virtual;
procedure wrAsVariant(a:variant);virtual;
function rdAsFloat:Extended;virtual;
procedure wrAsFloat(a:Extended);virtual;
function rdValues(const s:string):ILangValue;virtual;
public
{Returns integer representation of ILangValue if posible otherwise raises exception}
property AsInteger:Integer read rdAsInteger write wrAsInteger;
{Returns string representation of ILangValue if posible otherwise raises exception}
property AsString:STring read rdAsSTring write wrAsString;
{Returns boolean representation of ILangValue if posible otherwise raises exception}
property AsBoolean:Boolean read rdAsBoolean write wrAsBoolean;
{Returns Variant representation of ILangValue if posible otherwise raises exception}
property AsVariant:Variant read rdAsVariant write wrAsVariant;
{Returns float representation of ILangValue if posible otherwise raises exception}
property AsFloat:Extended read rdAsFloat write wrAsFloat;
{Execute value on given stack. if MustReturn is set to true }
{method have to leave one value to stack. It is expected that }
{Exec clears stack by DropFrame method. }
procedure Exec(S:IValStack;MustReturn:boolean);virtual;
{If this value has value named s returns true.}
function HasValue(const s:string):boolean;virtual;
{Accessor for holded values}
property Values[const s:string]:ILangValue read rdValues;
{Creates value equal to itself }
function CreateEqu:ILangValue;virtual;abstract;
{Returns value placed inside. For example for variable}
function GetValue:ILangValue;
{Sets value to given }
procedure SetValue(a:ILangValue);
end;
implementation
uses ValStack,VarLangValue;
function ILangValue.rdAsString;
begin
CantBeString;
end;
procedure ILangValue.wrAsString;
begin
CantBeString;
end;
function ILangValue.rdAsInteger;
begin
CantBeInteger;
end;
procedure ILangValue.wrAsInteger;
begin
CantBeInteger;
end;
function ILangValue.rdAsBoolean;
begin
CantBeBoolean;
end;
procedure ILangValue.wrAsBoolean;
begin
CantBeBoolean;
end;
function ILangValue.rdAsVariant;
begin
CantBeVariant;
end;
procedure ILangValue.wrAsVariant;
begin
CantBeVariant;
end;
function ILangValue.rdAsFloat;
begin
CantBeFloat;
end;
procedure ILangValue.wrAsFloat;
begin
CantBeFloat;
end;
function ILangValue.rdValues;
begin
ContainsNoValues;
end;
procedure ILangValue.Exec;
begin
NotExecutable;
end;
function ILangValue.HasValue;
begin
Result:=false;
end;
function ILangValue.GetValue;
Var s:TValStack;
v:TVarLangValue;
begin
v:=TVarLangValue.Create(nil); v.AsInteger:=0;
s:=TValStack.Create;
s.Push(v);
Exec(s,true);
Result:=s.Pop;
s.Free;
end;
procedure ILangValue.SetValue;
Var s:TValStack;
v:TVarLangValue;
begin
v:=TVarLangValue.Create(nil);
v.AsInteger:=1;
s:=TValStack.Create;
s.Push(a);
s.Push(v);
Exec(s,false);
s.Free;
end;
end.