Function Declarations

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Jennifer
Newbie
Newbie
Posts: 20
Joined: Tue Dec 07, 2004 5:00 am

Function Declarations

Post by Jennifer » Tue Jan 04, 2005 1:11 am

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.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Jan 04, 2005 9:15 am

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.
Marjan Slatinek,
http://www.steema.com

Jennifer
Newbie
Newbie
Posts: 20
Joined: Tue Dec 07, 2004 5:00 am

function declaration

Post by Jennifer » Tue Jan 04, 2005 3:31 pm

Thanks very much-Sometimes I wonder how we can be so obtuse aropund here. Probably form practice:-)

Jennifer

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Wed Jan 05, 2005 8:17 am

:lol:

Been there, done that :P
Marjan Slatinek,
http://www.steema.com

Post Reply