Bonjour
Je me lance avec Delphi Personal 6 dans une application mode console.
J'essaie de compiler le programme exemple suivant (trouvé sur un site anglais datant de 1997)
-------------------------------------------------
| program Con001;
| {$APPTYPE CONSOLE}
| uses Windows, SysUtils;
|
| const
| // Some common colors
| YellowOnBlue = FOREGROUND_GREEN OR FOREGROUND_RED OR
|
FOREGROUND_INTENSITY OR BACKGROUND_BLUE;
| WhiteOnBlue = FOREGROUND_BLUE OR FOREGROUND_GREEN OR
|
FOREGROUND_RED OR FOREGROUND_INTENSITY OR
| BACKGROUND_BLUE;
| RedOnWhite = FOREGROUND_RED OR FOREGROUND_INTENSITY OR
|
BACKGROUND_RED OR BACKGROUND_GREEN OR BACKGROUND_BLUE
| OR BACKGROUND_INTENSITY;
| WhiteOnRed = BACKGROUND_RED OR BACKGROUND_INTENSITY OR
|
FOREGROUND_RED OR FOREGROUND_GREEN OR FOREGROUND_BLUE
| OR FOREGROUND_INTENSITY;
|
| var
| ConHandle : THandle; // Handle to console window
| Coord : TCoord; // To store/set screen position
| MaxX, MaxY : Word; // To store max window size
| CCI : TConsoleCursorInfo;
| NOAW : LongInt; // To store results of some functions
|
| //-----------------------------------------
| // Get handle to console input
| //-----------------------------------------
| function GetConInputHandle : THandle;
| begin
| Result := GetStdHandle(STD_INPUT_HANDLE)
| end;
| //-----------------------------------------
| // Get handle to console output
| //-----------------------------------------
| function GetConOutputHandle : THandle;
| begin
| Result := GetStdHandle(STD_OUTPUT_HANDLE)
| end;
| //-----------------------------------------
| // Position cursor to X, Y
| //-----------------------------------------
| procedure GotoXY(X, Y : Word);
| begin
| Coord.X := X; Coord.Y := Y;
| SetConsoleCursorPosition(ConHandle, Coord);
| end;
| //-----------------------------------------
| // Clear Screen - fill it with spaces
| //-----------------------------------------
| procedure Cls;
| begin
| Coord.X := 0; Coord.Y := 0;
| FillConsoleOutputCharacter(ConHandle, ' ', MaxX*MaxY, Coord, NOAW);
| GotoXY(0, 0);
| end;
| //--------------------------------------
| // Show/Hide cursor
| //--------------------------------------
| procedure ShowCursor(Show : Bool);
| begin
| CCI.bVisible := Show;
| SetConsoleCursorInfo(ConHandle, CCI);
| end;
| //--------------------------------------
| // Initialize global variables
| //--------------------------------------
| procedure Init;
| begin
| // Get console output handle
| ConHandle := GetConOutputHandle;
| // Get max window size
| Coord := GetLargestConsoleWindowSize(ConHandle);
| MaxX := Coord.X;
| MaxY := Coord.Y;
| end;
| //---------------------------------------
| // Draw "status line"
| //---------------------------------------
| procedure StatusLine(S : String);
| begin
| Coord.X := 0; Coord.Y := 0;
| WriteConsoleOutputCharacter(ConHandle, PChar(S), Length(S)+1, Coord, NOAW);
| FillConsoleOutputAttribute (ConHandle, WhiteOnRed, Length(S), Coord, NOAW);
| end;
|
| //-----------------------------------------------------
| // Console Event Handler
| //-----------------------------------------------------
| function ConProc(CtrlType : DWord) : Bool; stdcall; far;
| var
| S : String;
| begin
| case CtrlType of
| CTRL_C_EVENT : S := 'CTRL_C_EVENT';
| CTRL_BREAK_EVENT : S := 'CTRL_BREAK_EVENT';
| CTRL_CLOSE_EVENT : S := 'CTRL_CLOSE_EVENT';
| CTRL_LOGOFF_EVENT : S := 'CTRL_LOGOFF_EVENT';
| CTRL_SHUTDOWN_EVENT : S := 'CTRL_SHUTDOWN_EVENT';
| else
| S := 'UNKNOWN_EVENT';
| end;
| MessageBox(0, PChar(S + ' detected'), 'Win32 Console', MB_OK);
| Result := True;
| end;
| {
| []---------------------------------------------------------------[]
| Main program - shows usage of some subroutines above and some
| of console API functions
| []---------------------------------------------------------------[]
| }
| var
| R : TSmallRect;
| Color : Word;
| OSVer : TOSVersionInfo;
| IBuff : TInputRecord;
| IEvent : DWord;
| Continue : Bool;
|
| begin
| // Initialize global variables
| Init;
| // Position window on screen
| With R do
| {!! 1.01 !!}
| begin
| Left := 10; Top := 10; Right := 40; Bottom := 40;
| end;
| {!! 1.01 !!}
| SetConsoleWindowInfo(ConHandle, False, R);
| // Set event handler
| SetConsoleCtrlHandler(@ConProc, True);
| // Check event handler
| GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
| // Change window title
| SetConsoleTitle('Console Demo');
| // Hide cursor
| ShowCursor(False);
| Coord.X := 0; Coord.Y := 0;
| // Set white text on blue
| Color := WhiteOnBlue;
| FillConsoleOutputAttribute(ConHandle, Color, MaxX*MaxY, Coord, NOAW);
| // Console Code Page API is not supported under Win95 - only GetConsoleCP
| Writeln('Console Code Page = ', GetConsoleCP);
| Writeln('Max X=', MaxX,' Max Y=', MaxY);
| Readln; // wait for user input
| Cls; // clear screen
| ShowCursor(True); // show cursor
| //
| // Use some Win32API stuff
| //
| OSVer.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
| GetVersionEx(OSVer);
| With OSVer do
| Begin
| Writeln('dwMajorVersion = ', dwMajorVersion);
| Writeln('dwMinorVersion = ', dwMinorVersion);
| Writeln('dwBuildNumber = ', dwBuildNumber);
| Writeln('dwPlatformID = ', dwPlatformID);
| End;
|
| //
| Readln; // wait for user input
| // Remove event handler
| SetConsoleCtrlHandler(@ConProc, False);
| Cls;
| //
| // "Message Loop"
| //
| Continue := True;
| While Continue do
| Begin
| ReadConsoleInput(GetConInputHandle, IBuff, 1, IEvent);
| Case IBuff.EventType of
| KEY_EVENT : Begin
| // Check for ESC Key and terminate program
|
If ((IBuff.KeyEvent.bKeyDown = True) AND
|
(IBuff.KeyEvent.wVirtualKeyCode = VK_ESCAPE)) Then
|
Continue := False;
| End;
| _MOUSE_EVENT : Begin
|
With IBuff.MouseEvent.dwMousePosition do
|
StatusLine(Format('%d, %d', [X, Y]));
| End;
| end;
| End {While}
| end.
| -----------------------------------------------------------------
Mais je suis bien refroidi par la volée d'erreur suivantes à la compilation
----------------------------------------------------------------------------
| [Erreur] Project1.dpr(54): Les types des paramètres VAR originaux et formels doivent être identiques
| [Erreur] Project1.dpr(83): Les types des paramètres VAR originaux et formels doivent être identiques
| [Erreur] Project1.dpr(84): Les types des paramètres VAR originaux et formels doivent être identiques
| [Erreur] Project1.dpr(142): Les types des paramètres VAR originaux et formels doivent être identiques
| [Erreur] Project1.dpr(177): Identificateur non déclaré : 'KeyEvent'
| [Erreur] Project1.dpr(182): Identificateur non déclaré : 'MouseEvent'
| [Erreur] Project1.dpr(182): 'DO' attendu(e) mais identificateur 'dwMousePosition' trouvé(e)
| [Erreur] Project1.dpr(187): Type Record, Object ou Class requis
| [Erreur] Project1.dpr(192): 'END' attendu(e) mais fin de fichier trouvé(e)
---------------------------------------------------------------------------
J'ai bien lu les explications de ces erreurs, mais cela ne m'a pas avancé..
Un Delphinaute pourrait-il me dire comment trouver une solution pour faire fonctionner ce programme en D6?
Merci d'avance.
Afficher la suite