Problems with ChartTool1GetText

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Valgardur
Newbie
Newbie
Posts: 3
Joined: Fri Feb 08, 2019 12:00 am

Problems with ChartTool1GetText

Post by Valgardur » Tue Mar 26, 2019 5:42 pm

I am having strange problems with "ChartTool1GetText", I need to display a different field value from the selected record, but it does not show.

This works:

Code: Select all

procedure TFForm.ChartTool1GetText(Sender: TMarksTipTool; var Text: string);
begin
  Text := 'Something';
end;
The text "Something" always shows.

But if I try to locate the record in question, nothing is displayed, not even a hard coded text.

Code: Select all

procedure TFForm.ChartTool1GetText(Sender: TMarksTipTool; var Text: string);
begin
  VinnuTafla.Locate('Faersla', Text, []);
  Text := 'Something';
end;
Nothing shows.

What I thought would work was something like this - I have set the Text to get the Record Id, which I have verified that works correctly.

Code: Select all

procedure TFForm.ChartTool1GetText(Sender: TMarksTipTool; var Text: string);
begin
  if VinnuTafla.Locate('Faersla', Text, []) then
  	Text := VinnuTaflaSvaedi.AsString
  else Text := '[not found]';
end;
The record is located correctly, and actually a bonus to see the dataset display follow in a separate panel.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problems with ChartTool1GetText

Post by Yeray » Mon Apr 01, 2019 1:09 pm

Hello,

I'd use the index to locate the correct fields. Otherwise, if you have repeated values it will find the first row with tat value, which will be wrong for the other fields in that row.
Ie, this seems to work without problems for me here:

Code: Select all

uses Series, DBTables, DateUtils;

var table1: TTable;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    datasource1: TDataSource;
begin
  table1:=TTable.Create(nil);
  table1.Active:=False;
  table1.TableName:='Test';
  table1.FieldDefs.Add('Date', ftDateTime);
  table1.FieldDefs.Add('Index', ftSmallint);
  table1.FieldDefs.Add('Value1', ftFloat);
  table1.FieldDefs.Add('Value2', ftFloat);

  table1.CreateTable;
  table1.Open;
  for i:=0 to 9 do
    table1.AppendRecord([Today+i-9, i, round(random*100), round(random*20)]);

  Chart1.View3D:=False;

  table1.First;
  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    Marks.Hide;
    XValues.DateTime:=True;
  end;

  while not table1.Eof do
  begin
    Chart1[0].AddXY(table1.FieldByName('Date').AsDateTime, table1.FieldByName('Value1').AsFloat);
    table1.Next;
  end;

  with (Chart1.Tools.Add(TMarksTipTool) as TMarksTipTool) do
  begin
    Style:=smsPointIndex;
    OnGetText:=ChartTool1GetText;
  end;

  datasource1:=TDataSource.Create(nil);
  datasource1.DataSet:=table1;
  DBGrid1.DataSource:=datasource1;
end;

procedure TForm1.ChartTool1GetText(Sender: TMarksTipTool; var Text: string);
begin
  if table1.Locate('Index', Text, []) then
     Text := 'Date: ' + table1.FindField('Date').AsString + sLineBreak +
             'Value1: ' + table1.FindField('Value1').AsString + sLineBreak +
             'Value2: ' + table1.FindField('Value2').AsString
  else
     Text := '[not found]';
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  table1.Close;
  table1.DeleteTable;
  table1.Free;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Valgardur
Newbie
Newbie
Posts: 3
Joined: Fri Feb 08, 2019 12:00 am

Re: Problems with ChartTool1GetText

Post by Valgardur » Tue Apr 16, 2019 12:57 pm

Thanks, (sorry for a late reply, but I had to take a break from this project)

But that is what I am doing, at least as far as I can see - my problem is that it does not return anything.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problems with ChartTool1GetText

Post by Yeray » Wed Apr 17, 2019 6:36 am

Hello,

There must be some difference somewhere. If you can't find it in your application you may try to extract the minimum parts from it to reproduce it, slowly converting it to the test I posted above. At some point you should be able to notice the difference.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Valgardur
Newbie
Newbie
Posts: 3
Joined: Fri Feb 08, 2019 12:00 am

Re: Problems with ChartTool1GetText

Post by Valgardur » Wed Apr 17, 2019 10:34 am

Thanks again for a quick reply..

I already did and as far as I can tell, whenever I do something with the dataset, it fails.

But this is a huge application, I also have a grid with the data, and as it moves to sync with selected dots, I think we will settle for that.

Post Reply