Board index » delphi » Console & GUI in one application

Console & GUI in one application

Hi,

How can I use the commands like WriteLn (Like Borland Pascal
7.0) to write some text to the console. But, I want in the
same application messageboxes too. So I can't compile the
application as a console application. The application would
have Console & GUI both possible

Quote
Ken White wrote:

> Marinus,

> See the help file on ParamCount and ParamStr.

> HTH

> Ken
> --
> Ken White
> kwh...@westelcom.com

> Clipper Functions for Delphi
> http://members.aol.com/clipfunc/

 Marinus den Breejen

-------------------------------------------------------------------
 Remove ANTISPAM from my email address to mail me.
-------------------------------------------------------------------

 It is a simple task to make things complex,
 but a complex task to make them simple
 come to my (dutch only) 3d home(page):
http://come.to/breejen
-------------------------------------------------------------------

 

Re:Console & GUI in one application


Hi Marinus,

On Wed, 17 Jun 1998 10:03:41 +0100, "(Marinus den Breejen)"

Quote
<MarinusbANTIS...@harley.nl> wrote:
>How can I use the commands like WriteLn (Like Borland Pascal
>7.0) to write some text to the console. But, I want in the
>same application messageboxes too. So I can't compile the
>application as a console application. The application would
>have Console & GUI both possible

Do you use Delphi 3. I use Delhpi 3 and I did not find any problems writing
a console application which uses WriteLn and show GUI components.

grtnx,
Richard

-----
Real programmers don't comment their code.
It was hard to write, it should be hard to understand.
-----
Richard Willemsen
http://www.xs4all.nl/~rwillems/

Re:Console & GUI in one application


Hoi Richard,

Hm, I get the error message:

Project OBJ.exe raised exception class EInOutError with
message 'I/O error 103'. Process stopped. Use Step or Run to
continue.

I can't find what error 103 and so I didn't know what the
problem is. I first test if there are parameters, and if so,
then I want to write them to the console with:
Writeln(paramstr(1)); I place this in the project file
(OBJ.pas), after Application.initalize but before
Application.CreateForm(Tform1,Form1);

Can you send me a part of code where you use this?

NB. I use Delphi 3

Marinus.

Quote
Richard Willemsen wrote:

> Hi Marinus,

> On Wed, 17 Jun 1998 10:03:41 +0100, "(Marinus den Breejen)"
> <MarinusbANTIS...@harley.nl> wrote:

> >How can I use the commands like WriteLn (Like Borland Pascal
> >7.0) to write some text to the console. But, I want in the
> >same application messageboxes too. So I can't compile the
> >application as a console application. The application would
> >have Console & GUI both possible

> Do you use Delphi 3. I use Delhpi 3 and I did not find any problems writing
> a console application which uses WriteLn and show GUI components.

> grtnx,
> Richard

> -----
> Real programmers don't comment their code.
> It was hard to write, it should be hard to understand.
> -----
> Richard Willemsen
> http://www.xs4all.nl/~rwillems/

--

 Marinus den Breejen

-------------------------------------------------------------------
 Remove ANTISPAM from my email address to mail me.
-------------------------------------------------------------------

 It is a simple task to make things complex,
 but a complex task to make them simple
 come to my (dutch only) 3d home(page):
http://come.to/breejen
-------------------------------------------------------------------

Re:Console & GUI in one application


Hi. The help file description about I/O error 103 is:

103 File not open Reported by CloseFile, Read Write, Seek, Eof, FilePos,
FileSize, Flush, BlockRead, or BlockWrite if the file is not open.

\Francois

Quote
(Marinus den Breejen) wrote:
> Hoi Richard,

> Hm, I get the error message:

> Project OBJ.exe raised exception class EInOutError with
> message 'I/O error 103'. Process stopped. Use Step or Run to
> continue.

Re:Console & GUI in one application


Hi,

Thanks. But, does anyone know how to open the console?

Marinus

Quote
Francois Labonte wrote:

> Hi. The help file description about I/O error 103 is:

> 103 File not open Reported by CloseFile, Read Write, Seek, Eof, FilePos,
> FileSize, Flush, BlockRead, or BlockWrite if the file is not open.

> \Francois

Re:Console & GUI in one application


Hi Marinus

On Thu, 18 Jun 1998 15:49:09 +0100, "(Marinus den Breejen)"

Quote
<MarinusbANTIS...@harley.nl> wrote:
>Hoi Richard,

>Hm, I get the error message:

>Project OBJ.exe raised exception class EInOutError with
>message 'I/O error 103'. Process stopped. Use Step or Run to
>continue.

This exception is raised when you use a WriteLn when the EXE is not build
as a console application (specified in the project options, linker).

Quote
>Can you send me a part of code where you use this?

<SOURCE CODE>
program Project1;

uses
  Forms, Dialogs;

{$R *.RES}

begin
  Application.Initialize;
  Application.Run;

  WriteLn('Console Test');

  ShowMessage('GUI Test');
end.
</SOURCE CODE>

This works fine in D3 with the Console options selected in the
project/linker options.

Don't forget, what ever you do, it is a console application. So it is not
posible to make this dynamical (I think) depending on your handling of the
arguments (ParamStr and ParamCount).

grtnx,
Richard

-----
Real programmers don't comment their code.
It was hard to write, it should be hard to understand.
-----
Richard Willemsen
http://www.xs4all.nl/~rwillems/

Re:Console & GUI in one application


Marunus,

See the Win32 API help file - in the Index page, type 'Console',
and you'll see lots of stuff...

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Quote
(Marinus den Breejen) wrote:

> Hi,

> Thanks. But, does anyone know how to open the console?

> Marinus

> Francois Labonte wrote:

> > Hi. The help file description about I/O error 103 is:

> > 103 File not open Reported by CloseFile, Read Write, Seek, Eof, FilePos,
> > FileSize, Flush, BlockRead, or BlockWrite if the file is not open.

> > \Francois

Re:Console & GUI in one application


Here's a component I wrote to help me with debugging via the console.

If you have any questions fill free to email me at d...@oz.net

-- Devin

unit udebug;

interface

uses Classes,Windows,SysUtils,Graphics;

Type
 TDebugCRT = Class(TComponent)
  private
   FEnabled: Boolean;

   procedure InitDebugWin;
  public
   hConsole : WORD;
   constructor Create(AOwner: TComponent); override;
   destructor Destroy; Override;
   procedure DebugStr(S:String);
   procedure DebugStrLf(S:String);
   procedure DebugInt(S:String;I:Integer);
   procedure DebugIntLf(S:String;I:Integer);
   procedure DebugLf;
   procedure DebugBuffer(S:String; B:Array of BYTE; Sz: Integer);
  published
   property Enabled:Boolean read FEnabled write FEnabled default TRUE;
 End;

procedure Register;

implementation

procedure Register;
begin
 RegisterComponents('System', [TDebugCRT]);
end;

constructor TDebugCRT.Create(AOwner: TComponent);
Begin
 inherited Create(AOwner);
 Enabled := TRUE;

 hConsole := 0;
End;

destructor TDebugCRT.Destroy;
Begin
 FreeConsole();
 hConsole := 0;
End;

Procedure TDebugCRT.InitDebugWin;
Begin
 AllocConsole();
 hConsole := GetStdHandle(STD_ERROR_HANDLE);
End;

Procedure TDebugCRT.DebugLf;
Const
 S : Array[0..4] of Char = #13#10#0;
Var
 R : Integer;
Begin
 WriteConsole(hConsole,@S,2,R,nil);
End;

Procedure TDebugCRT.DebugStr(S:String);
Var
 Str : Array[0..255] of Char;
 R : Integer;
Begin
 if (Enabled = FALSE) then
  exit;

 if (hConsole = 0) then
  InitDebugWin;
 strPCopy(Str,S);
 WriteConsole(hConsole,@Str,StrLen(Str),R,nil);
End;

Procedure TDebugCRT.DebugStrLf(S:String);
Begin
 DebugStr(S);
 DebugLf;
End;

Procedure TDebugCRT.DebugInt(S:String; I:Integer);
Var
 Str : Array[0..255] of Char;
 R : Integer;
Begin
 if (Enabled = FALSE) then
  exit;

 strPCopy(Str,Format('%s %d',[S,I]));

 if (hConsole = 0) then
  InitDebugWin;
 WriteConsole(hConsole,@Str,StrLen(Str),R,nil);
End;

Procedure TDebugCRT.DebugIntLf(S:String; I:Integer);
Begin
 if (Enabled = FALSE) then
  exit;

 DebugInt(S,I);
 DebugLf;
End;

Procedure TDebugCRT.DebugBuffer(S:String; B:Array of BYTE; Sz: Integer);
Var
 Str : Array[0..255] of Char;
 R : Integer;
 I : Integer;
Begin
 if (Enabled = FALSE) then
  exit;

 strPCopy(Str,Format('%s ',[S]));

 if (hConsole = 0) then
  InitDebugWin;
 WriteConsole(hConsole,@Str,StrLen(Str),R,nil);

 for I := 0 to Sz-1 do
 Begin
  R := B[I];
  strPCopy(Str,Format('%x  ',[R]));
  WriteConsole(hConsole,@Str,3,R,nil);
 End;

 DebugLf;
End;

Begin

end.

Quote
(Marinus den Breejen) wrote in message <35894408.2272D...@harley.nl>...
>Hi,

>Thanks. But, does anyone know how to open the console?

>Marinus

>Francois Labonte wrote:

>> Hi. The help file description about I/O error 103 is:

>> 103 File not open Reported by CloseFile, Read Write, Seek, Eof, FilePos,
>> FileSize, Flush, BlockRead, or BlockWrite if the file is not open.

>> \Francois

Other Threads