This is a tutorial how to make your own very simple custom command prompt in Delphi. There is not support for executing files, listing directories or things like that, just run your own commands. Maybe I'll extend the totorial later and explain how to do that. This tutorial is aimed at Delphi beginners. // First we need to define the name of the program. // In this case it's "MyCommandPrompt". program MyCommandPrompt; // Here we have to specify what type of application we // are going to make. This app is a console application. {$APPTYPE CONSOLE} // In this place we must tell Delphi what libraries to // use and include with our program. uses SysUtils, dialogs, windows; // Here we gonna define our variables and constants. var running: boolean; command: string; cLocn: coord; nWritten: dword; const version: string = '1.0'; author: string = 'MyName'; // This is here where all the fun begins :-) // This is the main code for our console application. begin // First we have to tell our program that it's running. // We do that by setting the "running" boolean variable to true. running:=true; // Prints the application-name and the current version to the screen. writeln('MyCommandPrompt v'+version); // This is our main loop. It's here we gonna make all our code. // I'll try to explain a bit: While "running" is = true our // program is running. If it's false then our program // will terminate. while running=true do begin write('$'); // Print "$" to the screen. readln(command); // Save the "command" variable. // Here we gonna run our commands. // The about command that prints the application-name, //version and author to the screen. if command='about' then begin writeln('MyCommandPrompt v'+version); writeln('Written by: '+author) end // The exit command. else if command='exit' then running:=false // Clear the screen. // Basicly it just fills the screen with spaces. else if command='clear' then begin cLocn.X := 0; cLocn.Y := 0; FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE ), ' ', 500 * 120, cLocn, nWritten); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE ), cLocn); end // Your own command. // This is just an example, how to make your own commands. else if command='mycommand' then writeln('This mycommand.') // If the command doesn't exist then print an error message. else writeln('Unknown command !'); end; end. // Created for http://www.progmania.dk Code (markup): Feel free to post any comments or questions.
Just a fast question , i know that delphi is old . anyone using it these days ? and in what kind of programming ?
Wow. I have never in my life seen Delphi code before today, and I have an ex-g/f that's w Delphi programmer... it looks vaguely similar to Python.
For Windows apps I'm hopelessly addicted to wxWidgets. Not only does it make porting to Linux and MacOS trivial, the interface is FAR FAR easier to comprehend than Win32 or MFC due to the consistency. That's the biggest thing that always bugged me about using Win32 - the fact that doing the same thing with different controls (i.e. a slider vs. spin control) used wildly different settings and arguments. Most people I've heard mention using Delphi say that they like it though.