?
Solved

Update 2nd form from main form

Posted on 2003-02-19
10
Medium Priority
?
249 Views
Last Modified: 2010-04-04
My application produces a set of data that changes over time. I am trying to display this data in a floating dialog box, which is a stayontop toolwindow. Ultimately I will want to display several of these floating windows (3 or 4).

Examples of the code I'm using are as follows:

procedure TForm1.StartButtonClick(Sender: TObject);
begin
  Form2.Show;  {display the floating window....}
  Timer1.Enabled := true;  {off we go....}
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
{Evaluate new data....}
  ...
  ...do some stuff...
  ...
{Update TChart on form 2....}
  with Form2.Chart1 do
  begin
    ...
    ...do some stuff...
    ...
  end;
end;


Although the application compiles and run's OK, the dialog box (Form2) is never updated, regardless of whether it, or the main form (Form1) has the focus.
I therefore assume that Form2 never processes messages. I tried showing Form2 as modal, but of course then Form1 didn't respond, presumably for the same reason.

I'm after some advice on the best approach to take. Specific code is not required, although I won't be offended if anyone includes some!

I do not particularly want to run Form2 in its own thread if I can avoid it; I already have several threads running and do not want to add more thread management overhead.
Do I need to force Form2 to process messages or am I doing something really stupid?

Thanks,
   FrankTheRat.


0
Comment
Question by:FrankTheRat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 60 total points
ID: 7980567
>Do I need to force Form2 to process messages or am I
>doing something really stupid?

normally i would guess it should work without any changes,
but you could try the refresh or repaint-method of
your form2 after your changes of the chart

just guessing

meikl ;-)
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 7980575
That should work fine... provided the Timer1Timer procedure finishes each time it's called, and you wait for the timer to go off again

e.g.

procedure Timer1Timer(...)
begin
  DoStuff;
  UpdateChart;
end;

is OK, but

proceure Timer1Timer(...)
begin
  while true do
  begin
    DoStuff
    UpdateChart;
  end;
end;

never gives Form2 a chance.
0
 
LVL 3

Expert Comment

by:sfock
ID: 7980588
try some Application.ProcessMessages within the do stuff
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:FrankTheRat
ID: 7980597
Thanks for trying. Just tried your suggestion. Neither
  Form2.Refresh;
nor
  Form2.Chart1.Refresh;
has any effect.

I copied the TChart to form1 and update both as follows:
{Update TChart on form 1....}
 with Chart1 do
 begin
   ...
   ...do some stuff...
   ...
 end;
{Update TChart on form 2....}
 with Form2.Chart1 do
 begin
   ...
   ...do the same stuff...
   ...
 end;

The Chart on Form1 updates correctly, nothing on form 2.

Still a confused Rat......

FrankTheRat
0
 
LVL 9

Expert Comment

by:mocarts
ID: 7980677
did you tried Form2.Chart1.Update; ?
wbr, mo.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7981349
Hi,

Perhaps we need more info about your OnTimer procedure because the following works fine here. There is one Label and one TChart (Bars style with one series) on the form2.

uses unit2;

var
  i: integer;

procedure TForm1.Button1Click(Sender: TObject);
begin
  i := 1;
  Form2.Show;
  Timer1.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Form2.Label1.Caption := IntToStr(i);
  with Form2.Series1 do begin
    Clear;
    Add(i+10,'aaa',clRed);
    Add(i+20,'bbb',clRed);
    Add(i+15,'ccc',clRed);
  end;
  i := i + 1;
end;

Regards, Geo
0
 
LVL 1

Author Comment

by:FrankTheRat
ID: 7982990
OK, you've all convinced me; I'm doing something stupid. Testing, I'll get back to you tomorrow.

Please wait......>_

FrankThe(Stupid)Rat
0
 
LVL 1

Author Comment

by:FrankTheRat
ID: 7983322
You are all, of course, completely correct; it works fine if you do it right.

I haven't yet discovered what I was doing wrong but I've just re-written the code from scratch and it works. Maybe we'll never know; I don't have the time to debug an error that no longer exists.

Thank you for your help, I have asked the moderators how I go about sharing the points between you
(kretzschmar, andrewjb, sfock, mocarts, geobul).

Thanks again,
    FrankTheFool
0
 

Expert Comment

by:modulo
ID: 7990235
Hi FrankTheRat,

I've refunded 80 points to enable you to accept the comment for one expert and to post "Points for <expertname>" Q's for the other experts in the same topic area.

Please:
1) Post the link to the original Q in the "Points for <expertname>" and
2) Add in the original Q a comment with the link to the "Points for <expertname>", thus the email notif will warn the expert.

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 1

Author Comment

by:FrankTheRat
ID: 7993310
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question