Solved

form in a thread

Posted on 2006-07-01
4
196 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 125 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 125 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

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 125
Tembedded WB animatid gifs not animated on some pcs 2 86
Twebbrowser in Fire monkey android scrolling to bottom 1 67
DBCtrlGrid, Delphi, Scroll 8 58
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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