Page 1 of 1

Function Declarations

Posted: Tue Jan 04, 2005 1:11 am
by 9340187
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.

Posted: Tue Jan 04, 2005 9:15 am
by Marjan
Hi.
the compiler says the calcuilate method cannot be found.
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:

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;
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:

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;
Of course, you can use more elaborate and complex approximations, but the basic idea is the same.

function declaration

Posted: Tue Jan 04, 2005 3:31 pm
by 9340187
Thanks very much-Sometimes I wonder how we can be so obtuse aropund here. Probably form practice:-)

Jennifer

Posted: Wed Jan 05, 2005 8:17 am
by Marjan
:lol:

Been there, done that :P