Writeln or ShowMessage - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Writeln or ShowMessage

Hi,
I am trying to make my life easier and write a generic error returning function.....so I dont have to rewrite modules depending on whether it will be a command line program or if its a GUI program (Yes I know command line programs can use ShowMessage...but thats not cool!)

So heres the question

How can I get a function to tell whether the program it is being run inside is a console application or a windowed program?

Cheers,
Johovishta

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi,
    : I am trying to make my life easier and write a generic error returning function.....so I dont have to rewrite modules depending on whether it will be a command line program or if its a GUI program (Yes I know command line programs can use ShowMessage...but thats not cool!)
    :
    : So heres the question
    :
    : How can I get a function to tell whether the program it is being run inside is a console application or a windowed program?
    :
    : Cheers,
    : Johovishta
    :
    Here is a very crude method, but it works:
    [code]
    try
    writeln('This program is a console program');
    except
    ShowMessage('This program is a GUI program');
    end;
    [/code]
    If you use writeln() with the Output file inside a GUI program, you will get a I/O 103 error.
    A better alternative is to check if the Output file variable is created or not, but I don't know how to code that.
  • johovishtajohovishta Posts: 20Member
    : : Hi,
    : : I am trying to make my life easier and write a generic error returning function.....so I dont have to rewrite modules depending on whether it will be a command line program or if its a GUI program (Yes I know command line programs can use ShowMessage...but thats not cool!)
    : :
    : : So heres the question
    : :
    : : How can I get a function to tell whether the program it is being run inside is a console application or a windowed program?
    : :
    : : Cheers,
    : : Johovishta
    : :
    : Here is a very crude method, but it works:
    : [code]
    : try
    : writeln('This program is a console program');
    : except
    : ShowMessage('This program is a GUI program');
    : end;
    : [/code]
    : If you use writeln() with the Output file inside a GUI program, you will get a I/O 103 error.
    : A better alternative is to check if the Output file variable is created or not, but I don't know how to code that.
    :

    Thanks Zibidian...
    works fine but is a bit crude ..Oh well who will know but you and I :)

  • zibadianzibadian Posts: 6,349Member
    : : : Hi,
    : : : I am trying to make my life easier and write a generic error returning function.....so I dont have to rewrite modules depending on whether it will be a command line program or if its a GUI program (Yes I know command line programs can use ShowMessage...but thats not cool!)
    : : :
    : : : So heres the question
    : : :
    : : : How can I get a function to tell whether the program it is being run inside is a console application or a windowed program?
    : : :
    : : : Cheers,
    : : : Johovishta
    : : :
    : : Here is a very crude method, but it works:
    : : [code]
    : : try
    : : writeln('This program is a console program');
    : : except
    : : ShowMessage('This program is a GUI program');
    : : end;
    : : [/code]
    : : If you use writeln() with the Output file inside a GUI program, you will get a I/O 103 error.
    : : A better alternative is to check if the Output file variable is created or not, but I don't know how to code that.
    : :
    :
    : Thanks Zibidian...
    : works fine but is a bit crude ..Oh well who will know but you and I :)
    :
    :
    I have found a better way: the IsConsole global variable.
Sign In or Register to comment.