Page 1 of 1

creating AnnotationTool by code

Posted: Wed Jun 28, 2006 4:16 pm
by 9339415
When I create an array of TAnnotationTools by code they do never display.
AnnotationTools created in the editor works as expected.
What am I doing wrong ?

MAXBARSPERSCREEN = 64;
MMBez : Array[0..MAXBARSPERSCREEN-1] of TAnnotationTool;

for i := 0 to globdat.vBarConf.nBalken - 1 do begin
MMBez := TAnnotationTool.Create( Chart1 );
MMBez.Text := Format( '%d', );
MMBez.Top := 30;
MMbez.Left := i * 50;
MMBez.Height := 10;
MMBez.Width := 40;
MMBez.Active := true;
MMBez.Visible := true;
end;

Posted: Thu Jun 29, 2006 8:42 am
by narcis
Hi mtspp,

This is because the tools are not properly added to the chart. You can do this:

Code: Select all

uses TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
const
  MAXBARSPERSCREEN = 64;
var
  MMBez : Array[0..MAXBARSPERSCREEN-1] of TTeeCustomTool;
  i: Integer;
begin

  for i := 0 to Length(MMBez)-1 do begin
    MMBez[i] := Chart1.Tools.Add(TAnnotationTool.Create( self ));
    with (MMBez[i] as TAnnotationTool) do begin
      Text := Format( '%d', [i] );
      Top := 30;
      Left := i * 50;
      Height := 10;
      Width := 40;
      Active := true;
      Visible := true;
    end;
  end;

end;

or this:

Code: Select all

uses TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
const
  MAXBARSPERSCREEN = 64;
var
  MMBez : Array[0..MAXBARSPERSCREEN-1] of TAnnotationTool;
  i: Integer;
begin

  for i := 0 to Length(MMBez)-1 do begin
    MMBez[i] := TAnnotationTool.Create( self );
    with MMBez[i] do begin
      Text := Format( '%d', [i] );
      Top := 30;
      Left := i * 50;
      Height := 10;
      Width := 40;
      Active := true;
      Visible := true;
    end;
    Chart1.Tools.Add(MMBez[i]);
  end;

end;