apophysis/2.10/Source/BaseVariation.pas

176 lines
4.3 KiB
ObjectPascal
Raw Normal View History

2005-09-11 06:30:54 -04:00
unit BaseVariation;
interface
type
TCalcFunction = procedure of object;
2005-09-11 06:30:54 -04:00
type
TBaseVariation = class
2005-09-11 06:30:54 -04:00
protected
procedure CalcFunction; virtual; abstract;
2005-09-11 06:30:54 -04:00
public
vvar: double;
2005-09-11 06:30:54 -04:00
FTx, FTy: ^double;
FPx, FPy: ^double;
class function GetName: string; virtual; abstract;
class function GetInstance: TBaseVariation; virtual; abstract;
2008-02-28 10:46:59 -05:00
function GetNrVariables: integer; virtual;
function GetVariableNameAt(const Index: integer): string; virtual;
2005-09-11 06:30:54 -04:00
function GetVariable(const Name: string; var Value: double): boolean; virtual;
function SetVariable(const Name: string; var Value: double): boolean; virtual;
function ResetVariable(const Name: string): boolean; virtual;
2005-09-11 06:30:54 -04:00
function GetVariableStr(const Name: string): string; virtual;
function SetVariableStr(const Name: string; var strValue: string): boolean; virtual;
2005-09-11 06:30:54 -04:00
procedure Prepare; virtual;
procedure GetCalcFunction(var Delphi_Suxx: TCalcFunction); virtual;
2005-09-11 06:30:54 -04:00
end;
TBaseVariationClass = class of TBaseVariation;
2008-02-24 07:43:30 -05:00
type
TVariationLoader = class
public
2009-04-20 03:42:36 -04:00
firstVariableIndex: integer;
2008-02-24 07:43:30 -05:00
function GetName: string; virtual; abstract;
function GetInstance: TBaseVariation; virtual; abstract;
function GetNrVariables: integer; virtual; abstract;
function GetVariableNameAt(const Index: integer): string; virtual; abstract;
end;
type
TVariationClassLoader = class (TVariationLoader)
public
constructor Create(varClass : TBaseVariationClass);
function GetName: string; override;
function GetInstance: TBaseVariation; override;
function GetNrVariables: integer; override;
function GetVariableNameAt(const Index: integer): string; override;
private
VariationClass : TBaseVariationClass;
end;
2005-09-11 06:30:54 -04:00
implementation
uses SysUtils;
2005-09-11 06:30:54 -04:00
{ TBaseVariation }
///////////////////////////////////////////////////////////////////////////////
2008-02-28 10:46:59 -05:00
function TBaseVariation.GetNrVariables: integer;
2005-09-11 06:30:54 -04:00
begin
Result := 0;
end;
///////////////////////////////////////////////////////////////////////////////
function TBaseVariation.GetVariable(const Name: string; var value: double): boolean;
begin
Result := False;
end;
function TBaseVariation.SetVariable(const Name: string; var value: double): boolean;
begin
Result := False;
end;
function TBaseVariation.ResetVariable(const Name: string): boolean;
var
zero: double;
begin
zero := 0;
Result := SetVariable(Name, zero);
end;
///////////////////////////////////////////////////////////////////////////////
function TBaseVariation.GetVariableStr(const Name: string): string;
var
value: double;
begin
if GetVariable(Name, value) then
2009-04-20 03:42:36 -04:00
Result := FloatToStr(value) //Format('%.6g', [value])
else
Result := '';
end;
function TBaseVariation.SetVariableStr(const Name: string; var strValue: string): boolean;
var
v, oldv: double;
begin
if GetVariable(Name, oldv) then begin
try
v := StrToFloat(strValue);
SetVariable(Name, v);
except
v := oldv;
end;
strValue := Format('%.6g', [v]);
Result := true;
end
else Result := false;
end;
///////////////////////////////////////////////////////////////////////////////
2008-02-28 10:46:59 -05:00
function TBaseVariation.GetVariableNameAt(const Index: integer): string;
begin
Result := ''
end;
2005-09-11 06:30:54 -04:00
///////////////////////////////////////////////////////////////////////////////
procedure TBaseVariation.Prepare;
2005-09-11 06:30:54 -04:00
begin
end;
///////////////////////////////////////////////////////////////////////////////
procedure TBaseVariation.GetCalcFunction(var Delphi_Suxx: TCalcFunction);
begin
Delphi_Suxx := CalcFunction;
end;
2008-02-24 07:43:30 -05:00
///////////////////////////////////////////////////////////////////////////////
{ TVariationClassLoader }
constructor TVariationClassLoader.Create(varClass : TBaseVariationClass);
begin
VariationClass := varClass;
end;
function TVariationClassLoader.GetName: string;
begin
Result := VariationClass.GetName();
end;
function TVariationClassLoader.GetInstance: TBaseVariation;
begin
Result := VariationClass.GetInstance();
end;
function TVariationClassLoader.GetNrVariables: integer;
2008-02-28 10:46:59 -05:00
var
hack : TBaseVariation;
2008-02-24 07:43:30 -05:00
begin
2008-02-28 10:46:59 -05:00
hack := GetInstance();
Result := hack.GetNrVariables();
hack.Free();
2008-02-24 07:43:30 -05:00
end;
function TVariationClassLoader.GetVariableNameAt(const Index: integer): string;
2008-02-28 10:46:59 -05:00
var
hack : TBaseVariation;
2008-02-24 07:43:30 -05:00
begin
2008-02-28 10:46:59 -05:00
hack := GetInstance();
Result := hack.GetVariableNameAt(Index);
hack.Free();
2008-02-24 07:43:30 -05:00
end;
2005-09-11 06:30:54 -04:00
end.