[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

form in a thread

Posted on 2006-07-01
4
Medium Priority
?
201 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
2 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

830 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