delphiteechart

TeeChart OnMouseDown fires FormActivate on parent form after opening child form


I'm using TeeChart Standard v2016 32bit VCL in Delphi 10.4

OnMouseDown on chart opens new form:

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Form2.Show;
end;

But after that FormActivate is called on parent form. I'm closing child form there.

procedure TForm1.FormActivate(Sender: TObject);
begin
  Form2.Close;
end;

Why is that event called and how to resolve that? In older version, Delphi 7 it was ok.


Solution

  • Use a flag:

    procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      FChartOpened := TRUE;
      Form2.Show;
    end;
    
    procedure TForm1.FormActivate(Sender: TObject);
    begin
      if FChartOpened then
         FChartOpened := FALSE
      else
         Form2.Close;
    end;