We are using Teechart VI and Delphi V and have a problem using functions. we made a simple example[below]. What happens is that
when we compile, the compiler says the calcuilate method cannot be found.
Thanks,
Jennifer
**********************************************************
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,TeEngine, Series, ExtCtrls, TeeProcs, Chart;
type
Tderivfunction=Class(TTeefunction);
TForm1 = class(TForm)
Chart1: TChart;
Series1: TFastLineSeries;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
Function Tderivfunction.calculate(SourceSeries:TchartSeries;
first,last:Longint):Double;
implementation
{$R *.DFM}
Function Tderivfunction.calculate(SourceSeries:TchartSeries;
first,last:Longint):Double;
VAR
kk:Integer;
startpoint,endpoint:LongInt;
BEGIN
IF First <>-1 Then startpoint:=first;
IF Last <>-1 Then endpoint:=Last;
FOR kk:=startpoint to endpoint Do
result:=sourceseries.getYvalue(kk+1)-
sourceseries.getYvalue(kk-1);
END;
procedure TForm1.FormActivate(Sender: TObject);
begin
end;
end.
Function Declarations
Hi.
But if you're calculating series 1st derivative, why don't you rather override the TTeeFunction.AddPoints method ? The following example should calculate series 1st derivative using simple forward difference formula:
Of course, you can use more elaborate and complex approximations, but the basic idea is the same.
That's true, because you haven't declared the Calculate method in TDerivFunction interface. Slightly different code is needed when you derive new class from existing class:the compiler says the calcuilate method cannot be found.
Code: Select all
TDerivFunction=Class(TTeefunction)
public
Function Calculate(SourceSeries:TChartSeries; FirstIndex,LastIndex:Integer):Double; override;
end;
function TDerivFunction.Calculate(SourceSeries: TChartSeries; FirstIndex,
LastIndex: Integer): Double;
var kk:Integer;
startpoint,endpoint: Integer;
begin
// Your implementation goes here
end;
Code: Select all
TDerivFunction=Class(TTeefunction)
public
procedure AddPoints(Source:TChartSeries); override;
end;
procedure TDerivFunction.AddPoints(Source: TChartSeries);
var dy,dx,doty: Double;
t: Integer;
begin
ParentSeries.Clear;
for t:=0 to Source.Count-2 do
begin
dx := Source.NotMandatoryValueList[t+1]-Source.NotMandatoryValueList[t];
dy := Source.MandatoryValueList[t+1]-Source.MandatoryValueList[t];
if dx <> 0.0 then
begin
doty := dy/dx;
ParentSeries.AddXY(Source.NotMandatoryValueList[t],doty);
end;
end;
end;
Marjan Slatinek,
http://www.steema.com
http://www.steema.com
function declaration
Thanks very much-Sometimes I wonder how we can be so obtuse aropund here. Probably form practice:-)
Jennifer
Jennifer