Board index » delphi » Need Help with console mode app in Delphi 2.0

Need Help with console mode app in Delphi 2.0

I'm in need of help on this:

I'm trying to do some CGI work in delphi 2.0.  I set the compiler to link for
a console mode app, but whenever I launch it it brings up a form and gives the
form the focus.  I can get to the Console and enter and recieve data, but for
a cgi program this is a flop.  Can anyone point me to the correct
procedure/resource for creating a true console mode app with delphi 2.0?

Thanks in advance.

                        Robert Harrold
                        r...@wwd.net

 

Re:Need Help with console mode app in Delphi 2.0


Quote
r...@wwd.net (Robert Harrold) wrote:

I have posted this one earlier :

Because the "wincrt" app's have vanished in Delphi 2.0, and the Win32  console
app is so poorly documented, and because a frequently asked question is : can I
have database access without visual components ?, and because I needed both, I
thought an example might be useful.

A console app is generated by checking the appropriate option in the linker page
of the project options. You can also write {$APPTYPE CONSOLE} as an alternative.
 You have to write the source code yourself in a .DPR file. The example also
shows how to access an SQL database without login prompt.

The code by itself serves no useful purpose, I just had to try out the thing.

Note that it uses 'Forms', but does not create or use a form,
and that the 'dpr' file is hand-written, not IDE generated.
The application.processmessages is needed to let 'Tapplication' do its stuff,
otherwise your console does not get the focus back.

I have a working CGI Delphi console application (works with Netscape FastTrack
on Windows NT), but I stripped the database part and moved it to a Delphi
"database server" app that listens to queries from the CGI app over a
DDE conversation link.

Hopes this helps.

Danny Heijl.

-----------------------------------------------------------------------
program Project1;

uses Windows,
  SysUtils,
  Controls,
  Forms,
  db,
  dbTables;

var
    q : Tquery;
    d : Tdatabase;
    s : String;
    i : Integer;
    r : Integer = 1;

begin
  Application.Initialize;
  Application.ProcessMessages;
try
  d := Tdatabase.Create(Nil);
  d.AliasName := 'watcom5_nt'; { BDE/ODBC alias }
  d.DatabaseName := 'watcom';
  d.Params.Add('USERNAME=dba;PASSWORD=sql');
  d.Loginprompt := False;
  d.Open;

  q := Tquery.Create(Nil);
  q.DatabaseName := 'watcom'; { database name or BDE alias if no Tdatabase}
  q.Name := 'Query1';
  write('Return starts query');
  readln(s);

  q.Close;
  q.SQL.Clear;
  q.SQL.Add('Select * from tel where telno >= 101');
  q.Open;

  q.First;
  while not q.Eof do begin
   writeln('Record : ' + IntToStr(r));
   for i := 0 to q.FieldCount - 1 do
   begin
     with q.FieldDefs.Items[i] do begin
       write( Name+':');
       writeln(q.FieldValues[Name]);
     end;
   end;
   writeln;
   q.Next;
  end;

  writeln('That's it !!'+#10+#13);
  Write('Return to exit');

  readln(s);

finally
  d.Destroy;
  q.Destroy;
end;

end.
------------------------------------------------------------------------

Quote
>I'm in need of help on this:
>I'm trying to do some CGI work in delphi 2.0.  I set the compiler to link for
>a console mode app, but whenever I launch it it brings up a form and gives the
>form the focus.  I can get to the Console and enter and recieve data, but for
>a cgi program this is a flop.  Can anyone point me to the correct
>procedure/resource for creating a true console mode app with delphi 2.0?
>Thanks in advance.
>                    Robert Harrold
>                    r...@wwd.net

Danny.He...@cevi.be    http://www.cevi.be/pp/danny/dhe.htm

AT WORK :      | HOME :
---------------------------------
Danny Heijl    |
CEVI VZW       | Danny Heijl
Bisdomplein 3  | Winterstraat 4
9000 Gent      | 9000 Gent
Belgium        | Belgium
---------------------------------

Re:Need Help with console mode app in Delphi 2.0


H|!

Quote
>I'm trying to do some CGI work in delphi 2.0.  I set the compiler to link for
>a console mode app, but whenever I launch it it brings up a form and gives the
>form the focus.  I can get to the Console and enter and recieve data, but for
>a cgi program this is a flop.  Can anyone point me to the correct
>procedure/resource for creating a true console mode app with delphi 2.0?

If you want to write an MS-DOS program then you'd have DCUs for MS-DOS.
If you want to create a Windows program without a form then you have not got
to choose a console application type. The only thing you have to do is to
close a form module. If you don't want to use TApplication then you have to
unlink FORMS.DCU from your program(delete it from uses line).

                                           SBR.
---
Bu...@stk.ksu.ras.ru
{Excuse me please for my bad russian, my native language is Borland Pascal 8.3}

Re:Need Help with console mode app in Delphi 2.0


Quote
r...@wwd.net (Robert Harrold) wrote:
>I'm in need of help on this:
>I'm trying to do some CGI work in delphi 2.0.  I set the compiler to link for
>a console mode app, but whenever I launch it it brings up a form and gives the
>form the focus.  I can get to the Console and enter and recieve data, but for
>a cgi program this is a flop.  Can anyone point me to the correct
>procedure/resource for creating a true console mode app with delphi 2.0?
>Thanks in advance.

Click on new application and you will get project1.dpr and unit1.pas,
as yet unsaved. Then click view project manager, click the unit1 line,
click the red minus, and don't save changes to unit1. Now you just
have project1.dpr. Click view/ project source and edit it to look
something like the following, to have something to test redirection
of i/o:
//------------------------------------------------------------
program Project1;
{$APPTYPE CONSOLE}
uses Windows;
var
  s:String;
  i:DWORD;
begin
  for i:= 1 to 5 do begin
    Readln(s);
    Writeln(s);
  end;
end.
//------------------------------------------------------------
Compile and save as First5 (or whatever you like).
Go into an NT DOS prompt, find your way to the directory where
First5.exe is, and try typing something like:
  first5 <first5.dpr
or
  dir/s/b | first5
or
  first5
by itself, and you'll get to type 5 lines that are each
successively repeated on the screen each time you finish one.

HTH,
Regards,
Bengt Richter

Other Threads