![]() |
TextColor für Delphi
Hi,
Wenn man in Delphi eine Konsolenanwendung macht, dann programmiert man ja praktisch Pascal (wie auch mit VCL^^). In TurboPascal kann man Text einfärben mit TextColor(Farbe). Den Befehl gibts in Delphi aber irgendwie nicht mehr... Die ganzen Sachen mit TextColor etc steht in Turbo-Pascal in der Unit crt. Ich wollte jetzt die Pascal Unit in ne Delphi Unit umwandeln um die Sachen wie TextColor nutzen zu können. Die crt Unit sieht so aus:
Delphi-Quellcode:
Naja das Problem ist: Wo sind die proceduren und Funktionen da bitte "ausgefüllt" ? -.-{*******************************************************} { } { Turbo Pascal Version 7.0 } { CRT Interface Unit } { } { Copyright (C) 1988,92 Borland International } { } {*******************************************************} unit Crt; {$D-,I-,S-} interface const { CRT modes } BW40 = 0; { 40x25 B/W on Color Adapter } CO40 = 1; { 40x25 Color on Color Adapter } BW80 = 2; { 80x25 B/W on Color Adapter } CO80 = 3; { 80x25 Color on Color Adapter } Mono = 7; { 80x25 on Monochrome Adapter } Font8x8 = 256; { Add-in for ROM font } { Mode constants for 3.0 compatibility } C40 = CO40; C80 = CO80; { Foreground and background color constants } Black = 0; Blue = 1; Green = 2; Cyan = 3; Red = 4; Magenta = 5; Brown = 6; LightGray = 7; { Foreground color constants } DarkGray = 8; LightBlue = 9; LightGreen = 10; LightCyan = 11; LightRed = 12; LightMagenta = 13; Yellow = 14; White = 15; { Add-in for blinking } Blink = 128; var { Interface variables } CheckBreak: Boolean; { Enable Ctrl-Break } CheckEOF: Boolean; { Enable Ctrl-Z } DirectVideo: Boolean; { Enable direct video addressing } CheckSnow: Boolean; { Enable snow filtering } LastMode: Word; { Current text mode } TextAttr: Byte; { Current text attribute } WindMin: Word; { Window upper left coordinates } WindMax: Word; { Window lower right coordinates } { Interface procedures } procedure AssignCrt(var F: Text); function KeyPressed: Boolean; function ReadKey: Char; procedure TextMode(Mode: Integer); procedure Window(X1,Y1,X2,Y2: Byte); procedure GotoXY(X,Y: Byte); function WhereX: Byte; function WhereY: Byte; procedure ClrScr; procedure ClrEol; procedure InsLine; procedure DelLine; procedure TextColor(Color: Byte); procedure TextBackground(Color: Byte); procedure LowVideo; procedure HighVideo; procedure NormVideo; procedure Delay(MS: Word); procedure Sound(Hz: Word); procedure NoSound; // Komischweise fehlt hier das Folgende: { implemetation end. } Gar nicht. Aber woher weis Pascal was es tun soll ? Und viel wichtiger: Woher bekomm ich die Funktionen/Proceduren ? :gruebel: PS: Die Datei heißt: crt.int... wobei pascal immer tpu dateien zum einbinden braucht :gruebel: Aber es gibt keine crt.tpu :wall: Gruß Michael |
Re: TextColor für Delphi
Probier mal den Befehl
Delphi-Quellcode:
aus der Unit Windows. Dafür brauchst du das Handle des Konsolenfensters. Aber woher krieg ich das :gruebel:
SETTEXTCOLOR
|
Re: TextColor für Delphi
Zitat:
Dafür brauch ich ja das Handle meiner Anwendung.. Aber so was wie Application.Handle gibts in ner Konsolenanwendung nicht.. Und ich suche sicher nicht mit FindWindow mein eigenes Fenster -.-^^ |
Re: TextColor für Delphi
Zitat:
Und im Notfall kannst du ja immer noch die Forms einbinden. :? wenn ich application.handle aus der forms verwende und mit getwindowdc in die hdc umwandle, scheints nicht zu klappen... |
Re: TextColor für Delphi
Das Problem ist das wir das grad im Info Unterricht mit Pascal arbeiten. Und wenn Pascal mal wieder nicht funktioniert dann machen wir Delphi Konsolenanwendungen... Ist ja praktisch (fast) das Gleiche. Bis auf die Tatsache das es halt einige Pascal Befehle nicht mehr gibt.. Und ich glaube wenn ich denen dann sage das sie die Textfarbe nur ändern können wenn sie vorher das Handle ("Handle? Kann man das essen?" ^^) der Anwendung herausfinden müssen dann lassen die das lieber sein :mrgreen:
Ich könnte vielleicht ne eigene Unit machen wo dann ne TextColor Methode mache die dann von SetTextColor "abgeleitet" ist. Aber naja mal sehn... EDIT: Zitat:
Hat sone Konsolenanwendung überhaupt ein Handle ? ^^ Bzw Application hat ja mit Konsolenanwendungen normalerweise nix zu tun.. (oder?) |
Re: TextColor für Delphi
![]() So gehts:
Delphi-Quellcode:
Farbwert nimmt Werte von 0 bis 255 an.
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FarbWert);
...:cat:... |
Re: TextColor für Delphi
Ok, danke Sakura.
Was mich noch interessieren würde wäre GotoXY und TextBackground für Delphi... (Dafür muss ich doch jetzt keinen neuen Thread aufmachen oder ?) |
Re: TextColor für Delphi
Zitat:
0 - Schwarz 1 - Blau 2 - Grün 3 - Dunkles Cyan 4 - Rot 5 - Lila 6 - bräunliches Gelb 7 - "dunkles weiß" 8 - "helles grau" 9 - hellblau 10 - hellgrün 11 - cyan 12 - knallrot 13 - grelles lila 14 - gelb 15 - schneeweiß ...:cat:... Diese Wert um 4 Bit (shl 4) nach links verschieben und dann wird die Hintergrundfarbe entsprechend gesetzt. ...:cat:... |
Re: TextColor für Delphi
Zitat:
Delphi-Quellcode:
var
CP: _COORD; ... CP.X := 5; CP.Y := 4; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), CP); Zitat:
...:cat:... |
Re: TextColor für Delphi
P.S.: Alles mit 2 Minuten Googeln erledigt. (VB Source nach Delphi portiert und fertig!)
...:cat:... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz