Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create your first console application to interact with forms Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Jul-03
Category
Others
Language
Delphi 5.x
Views
183
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Subha Narayanan

Interaction between your Console applications and your forms

Answer:

This code demonstrates how to combine console API with usual forms 

Create a new -> console application and save it as listing2 
Copy the given code in to the console application 
Create a form in the same project with name frmDialog1.dfm and dialog1.pas 
In the form put three RadioButtons 
Now build and run the application 
Shift the focus to the console application and type 1 or 2 or 3 

Based on the number typed the Radiobutton in the form will be clicked automatically 
When u press ctrl + c the application exits

1   program listing2;
2   {$APPTYPE CONSOLE}
3   uses
4     SysUtils, Windows, Messages, Forms,
5     Dialog1 in 'Dialog1.pas' {frmDialog1};
6   
7   var
8     hInput: THandle;
9     inRec: TInputRecord;
10    dwCount: DWORD;
11  
12  begin
13    {Create a Form in the usual way. The Forms unit ensures that
14    the Application object is around to "own" the form.}
15  
16    write('Creating the first Dialog Box...');
17    frmDialog1 := TfrmDialog1.Create(Application);
18    frmDialog1.Show;
19    Writeln('done.');
20  
21    Writeln('Press 1, 2 or 3 to change the dialog box. Press Ctrl+ C to exit');
22  
23    {Handle the Console input till the user cancels}
24    hInput := GetStdHandle(STD_INPUT_HANDLE);
25    {GetStdHandle - Returns handle for Standard input/output device}
26  
27    while True do
28    begin
29      {Avoid blocking on user input, so the forms have a chance
30      to operate as normal. If we had a message queue present, this
31      would be a normal message dispatch loop.}
32      Application.ProcessMessages;
33      if WaitForSingleObject(hInput, 0) = WAIT_OBJECT_0 then
34      begin
35        ReadConsoleInput(hInput, inRec, 1, dwCount);
36        if (inRec.EventType = KEY_EVENT) and inRec.Event.KeyEvent.bKeyDown then
37        begin
38          case inRec.Event.KeyEvent.AsciiChar of
39            '1':
40              begin
41                Writeln('->1');
42                frmDialog1.RadioButton1.Checked := True;
43              end;
44  
45            '2':
46              begin
47                Writeln('->2');
48                frmDialog1.RadioButton2.Checked := True;
49              end;
50            '3':
51              begin
52                Writeln('->3');
53                frmDialog1.RadioButton3.Checked := True;
54              end;
55          end;
56        end;
57      end;
58    end;
59  end.
 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC