unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
    FieldFunction=function(x:double; y:double):double;cdecl;

procedure CreateChart(); cdecl; external 'CChartu.dll' name '?CreateChart@Classless@@YAXXZ'
procedure DestroyChart(); cdecl; external 'CChartu.dll' name '?DestroyChart@Classless@@YAXXZ'
function Attach(hWnd:HWND):integer; cdecl; external 'CChartu.dll' name '?Attach@Classless@@YAHPAUHWND__@@@Z'
function SetType(charttype:integer):boolean; cdecl; external 'CChartu.dll' name '?SetType@Classless@@YA_NH@Z'
procedure SetFieldFcn(field:FieldFunction); cdecl; external 'CChartu.dll' name '?SetFieldFcn@Classless@@YAXP6ANNN@Z@Z'
procedure SetPlotRange(x1:double; x2:double; y1:double; y2:double); cdecl; external 'CChartu.dll' name '?SetPlotRange@Classless@@YAXNNNN@Z'
procedure SetTitle(title:PWideChar); cdecl; external 'CChartu.dll' name '?SetTitle@Classless@@YAXPB_W@Z'
function SetConfineRect(rect:TRect):Boolean; cdecl; external 'CChartu.dll' name '?SetConfineRect@Classless@@YA_NUtagRECT@@@Z'
procedure ReDraw(); cdecl; external 'CChartu.dll' name '?ReDraw@Classless@@YAXXZ'

function fieldfcn(x:double; y:double):double;cdecl;
begin
    fieldfcn:=1.0/(x*x + y*y + 1.0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    CreateChart();
    Attach(Handle);
    SetType(6);
    SetTitle('Delphi±êÌâ');
    SetFieldFcn(@fieldfcn);
    SetPlotRange(-2.0, 2.0, -2.0, 2.0);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    DestroyChart();
end;

procedure TForm1.FormResize(Sender: TObject);
var
    lpRect: TRect;
begin
    Windows.GetClientRect(Handle, lpRect);
    SetConfineRect(lpRect);
    ReDraw();
end;

end.
 