TChart AddXY

Hi to all,
I've tried to add the AddXY method or a TChartSeries with following results:

[FIRST TEST]
In the MainProgram:
procedure TChartTestFrm.BitBtn1Click(Sender: TObject);
begin
    fsScript1.Clear;
    { script text }
    fsScript1.Parent := fsGlobalUnit;
    fsScript1.Lines := fsSyntaxMemo1.Lines;
    fsScript1.AddForm(ChartTestFrm);

    with fsScript1.AddClass(TChartSeries, 'TComponent')

//////////////////////////////////////////////////////////
    do AddMethod('function AddXY(Const AXValue, AYValue: Double; Const AXLabel: String; AColor: TColor) : Longint',CallMethod); // This gives error
//////////////////////////////////////////////////////////
    If Not fsScript1.Compile Then
    Begin
        Exit;
    End;
    fsScript1.Execute;
end;

(...)

function TChartTestFrm.CallMethod(Instance: TObject; ClassType: TClass;const MethodName: String; var Params: Variant): Variant;
begin
  Result := 0;

  if ClassType = TChartSeries then
  begin
    if MethodName = 'CLEAR' then
    else if MethodName = 'ADDXY' then
      TChartSeries(Instance).AddXY(Params[0], Params[1], Params[2], Params[3]) //Carlo
  end
end;

When I execute the program, the AddMethod call gives an Access violation error.


[Second test -this works- : modify source unit fs_ichartrtti.pas]
On Row 84:
    with AddClass(TChartSeries, 'TComponent') do
    begin
      AddMethod('procedure Clear', CallMethod);
      AddMethod('procedure Add(const AValue: Double; const ALabel: String; AColor: TColor)', CallMethod);
//////////////////////////////////////////////////////////
      AddMethod('function AddXY(Const AXValue, AYValue: Double; Const AXLabel: String; AColor: TColor) : Longint',CallMethod); //Carlo
//////////////////////////////////////////////////////////
    end;

(...)
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
  const MethodName: String; Caller: TfsMethodHelper): Variant;
begin
  Result := 0;

  if ClassType = TChartSeries then
  begin
    if MethodName = 'CLEAR' then
      TChartSeries(Instance).Clear
    else if MethodName = 'ADD' then
      TChartSeries(Instance).Add(Caller.Params[0], Caller.Params[1], Caller.Params[2])
//////////////////////////////////////////////////////////
    else if MethodName = 'ADDXY' then
      TChartSeries(Instance).AddXY(Caller.Params[0], Caller.Params[1], Caller.Params[2], Caller.Params[3]) //Carlo
//////////////////////////////////////////////////////////
  end

How should I use AddMethod in my program instead of altering FsScript source code (and loose my code on each fsScript upgrade) ???

I think fsScript is great, really, but I think also that with al little more effort (adding ALL the methods and properties) this would be GREAT.

I'm waiting for response.

Ciao,
Geppo Darkson.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.