?
Solved

Update 2nd form from main form

Posted on 2003-02-19
10
Medium Priority
?
253 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

578 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