Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

form in a thread

Posted on 2006-07-01
4
Medium Priority
?
199 Views
Last Modified: 2010-04-05
I need some codes for 2 forms run simutaniously.
One(a) is main form. Another(b) is a form to monitor some system status. when (b) get the pc system  information, it will exchange data with (a), (a) will display some data on itself.

What is the solution for this, does it need put (b) in a thread?

Welcome any comment.

Thanks

Z W
0
Comment
Question by:wangzheng
[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
4 Comments
 

Accepted Solution

by:
SergiuAdrian earned 500 total points
ID: 17025513
if you want to display the pc system info on form (a) only, you don't have to create another form (b) if you don't use it to display anything.

just create another unit and make a thread class. here is some basic code for it:

----------------------------------------------------------------------------------------
unit SomeUnitWithThread;

interface

uses
  Classes;

type
  TGetInfoThread = class(TThread)
  private
    SomeInfo : string;
    { Private declarations }
  protected
    procedure Execute; override;
    function GetSomeInfo() : string;
  end;

implementation

procedure TGetInfoThread.Execute;
begin
  { some code to get PC info. don't forget to check
    if the thread is terminated and stuff. to learn how
   to use threads see delphi's help or search the internet,
   for example here:  

   http://delphi.about.com/od/kbthread/index.htm?terms=threads+delphi

  }
end;

function TGetInfoThread.GetSomeInfo():string;
begin
   result := SomeInfo;
end;
end.
----------------------------------------------------------------------------------------

you then make a thread object in the main form:

--------------------------------------
var Form1 : TForm1;
     GetPcInfo: TGetInfoThread;
.........
//now instantiate after the main form is created
procedure TForm1.FormCreate(Sender: TObject);
begin
GetPCInfo := TGetInfoThread.Create(false);// false means the thread is running,
                                                               //true means the thread is suspended after the creation.
.......
--------------------------------------

of course, you can declare the TGetInfoThread class in the same unit with the main form, but i like to have the threads in different units.

0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 500 total points
ID: 17028024
As long as both forms aren't doing tight loops, you don't have to do anything.
eg. If you are using TTImer's to do the checking, or you are doing "Application.ProcessMessages" in any tight loops, so that both forms can continue to process.

Here's an example just using timers
make sure unit2 is in unit1's uses lise, and unit1 is in unit2's uses list (the uses under implementation)
so that you don't get the  cyclic reference issue.
e.g.

unit Unit1;

interface
uses forms,... etc....   , unit2;

implementation

procedure Form1Timer1Timer(sender: TObject);
begin
    timer1.enabled := false;
    try
        form2.TimeLabel.Caption := TimeToStr(now);
    finally
        timer1.enabled := true;
    end;
end;


unit Unit1;

interface
uses forms, ....etc;

implementation

uses unit1;

procedure Form2Timer2Timer(sender: TObject);
begin
    timer2.enabled := false;
    try
        form1.DateLabel.Caption := DateToStr(now);
    finally
        timer2.enabled := true;
    end;
end;




0

Featured Post

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.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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