Watch, Follow, &
Connect with Us

Welcome, Guest
Guest Settings
Help

Thread: Event driven components cause changes to teechart, but not in FormCreate


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Mar 20, 2017 10:23 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Toby Dobbs

Posts: 76
Registered: 9/24/16
Event driven components cause changes to teechart, but not in FormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2017 9:25 AM
Hi,

I have a form which contains a number of event-driven components for setting the axis ranges, increment, titles etc. on a teechart. Under normal working circumstances these function as expected but when I forcibly click on a button to initiate a sequence of these actions inside the FormCreate method only some appear to work. If I call this method twice then the chart updates as I would expect. Can you help me understand this and, if possible, suggest a cleaner way of doing things?
Remy Lebeau (Te...


Posts: 8,641
Registered: 12/23/01
Re: Event driven components cause changes to teechart, but not inFormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2017 9:58 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby wrote:

Can you help me understand this and, if possible, suggest a cleaner
way of doing things?

Please show your actual code, and explain what changes are not taking effect
as expected.

--
Remy Lebeau (TeamB)
Toby Dobbs

Posts: 76
Registered: 9/24/16
Re: Event driven components cause changes to teechart, but not inFormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 2:11 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Please show your actual code, and explain what changes are not taking effect
as expected.

--
Remy Lebeau (TeamB)

The actual code looks something like this

  type
    TMyForm = type(TForm)
      Button1: TButton;
      Edit1: TEdit;
      Spin1: TSpin;
      Button2: TButton;
      ...
  end;
 
  procedure TMyForm.Button1OnChange(Sender: TObject);
  begin
    ...invert axis, for example
  end;
 
  procedure TMyForm.Edit1OnChange(Sender: TObject);
  begin
    ...set minimum value on axis, for example
  end;
 
  procedure TMyForm.Spin1OnChange(Sender: TObject);
  begin
    ...set maximum value on axis, for example
  end;
 
  procedure TMyForm.Create(...);
  begin
    Button2.Click;  
  end;
 
  procedure TMyForm.Button2Click(Sender: TObject);
  begin
    Button1.Click;
    Edit1.Text := '4';
    Spin1.Value := 7;
  end;


I hope this helps
Remy Lebeau (Te...


Posts: 8,641
Registered: 12/23/01
Re: Event driven components cause changes to teechart, but notinFormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 10:23 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby wrote:

procedure TMyForm.Button1OnChange(Sender: TObject);

TButton does not have an OnChange event, I assume you meant OnClick instead.

procedure TMyForm.Create(...);
begin
Button2.Click;
end;

Rather than invoking event handlers like that, you should move the relavant
actions to their own methods and then you can call them directly when needed,
eg:

type
  TMyForm = type(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Spin1: TSpin;
    Button2: TButton;
    ...
  private
    procedure InvertAxis;
    procedure SetAxisMinValue;
    procedure SetAxisMaxValue;
    procedure UpdateUI;
    ...
  end;
 
procedure TMyForm.InvertAxis;
begin
  ...invert axis...
end;
 
procedure TMyForm.SetAxisMinValue;
begin
  ...set minimum value on axis...
end;
 
procedure TMyForm.SetAxisMaxValue;
begin
  ...set maximum value on axis...
end;
 
procedure TMyForm.UpdateUI;
begin
  InvertAxis;
  Edit1.Text := '4';
  Spin1.Value := 7;
end;
 
procedure TMyForm.FormCreate(Sender: TObject);
begin
  UpdateUI;
end;
 
procedure TMyForm.Button1Click(Sender: TObject);
begin
  InvertAxis;
end;
 
procedure TMyForm.Edit1Change(Sender: TObject);
begin
  SetAxisMinValue;
end;
 
procedure TMyForm.Spin1Change(Sender: TObject);
begin
  SetAxisMaxValue;
end;
 
procedure TMyForm.Button2Click(Sender: TObject);
begin
  UpdateUI;
end;


--
Remy Lebeau (TeamB)
Alex Belo

Posts: 535
Registered: 10/8/06
Re: Event driven components cause changes to teechart, but not in FormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 9:01 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby Dobbs wrote:

I have a form which contains a number of event-driven components for
setting the axis ranges, increment, titles etc. on a teechart. Under
normal working circumstances these function as expected but when I
forcibly click on a button to initiate a sequence of these actions
inside the FormCreate method only some appear to work. If I call this
method twice then the chart updates as I would expect. Can you help
me understand this and, if possible, suggest a cleaner way of doing
things?

1) Try another form's event (FormShow, for example).

or

2) Put timer with 10 ms period on the form, start it in FormCreate. On
the first timer event disable the timer (i.e. timer fires only 1 time
after all form's startup events and disables itself) and perform your
initialization.

--
Alex
John Treder

Posts: 330
Registered: 8/2/02
Re: Event driven components cause changes to teechart, but not in FormCreate  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 10:00 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby Dobbs wrote:

Hi,

I have a form which contains a number of event-driven components for setting the axis ranges, increment, titles etc. on a teechart. Under normal working circumstances these function as expected but when I forcibly click on a button to initiate a sequence of these actions inside the FormCreate method only some appear to work. If I call this method twice then the chart updates as I would expect. Can you help me understand this and, if possible, suggest a cleaner way of doing things?

The incomplete code you posted later isn't much help.
Sometimes, if the code in the button click handler calls an object that should be visible, but isn't yet shown because the OnCreate handler comes before the form is visible on the screen, you'll get such an error. When I have that kind of issue, i post (not send) a message to the form and then handle it. That has always worked for me. Putting the "after form is visible" stuff in an OnShow event handler will work if the stuff can be run more than once.

--
don't Tred on me
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02