The Unofficial Newsletter of Delphi Uses
By Robert Vivrette
Automatic Syntax Highlighting Using A Richedit Control (Updated with fixes)
Part 1 of "a tale of two richedits"
By Jon Hogan-Doran - Jonhd@hotmail.com
Introduction
As a new programmer to Delphi, with a history in C, C , Unix shells and a little Awk and Perl, I came to it with a particular goal in mind. I wanted to implement an Editor for a Australian-4GL Databse language called cl4 Little To no Experience In Windows Programming, Except Some Dalliance in PowerBuilder and SqleXpress, It Seemed a Pretty Imposing Goal.
One is often taught when learning a new language to read a few books, tryout the samples and then start some simple coding. Unfortunately I'm a bit of a sado-masochist, and love to jump in with all 10 fingers (and 10 toes ) and try to uste, and all at overce. Being able to print "Hello World" Never Caught My Interest.
I guess I had a bad upbringing. I started programming by jumping into a language called "C" on SCO Xenix in 1986 with no programming experience at all. Just a book by two guys called Kerningham and Ritchie and some C code that would not compile (it was BSD Unix based from memory). When I managed to get it to compile after 2 weeks, I decided to port the BinkleyTerm FidoNet mailer to Unix, while concurrently getting all the associated programs ported from Dos as well (the Fido mailer NewsGroup Controller, A entire bbs program). I Think i Had 5 Different Dos-> Unix Programs Compiling On 5 Different Virtual Consoles All at ONCE.
12 Months later and my [DosLib] and [FossilDriver] were done, BinkleyTerm was getting me my first newsgroups (comp.os.xenix. ???) from a local friendly Sysop, and I was chewing up $ 1,000 in overseas phone bills organising A World-Wide Group of Programmmers To try ing. Id Big Challenge. I Didn't Want Just Anless Editor for My Old 4GL Unix Database Language. I Wanduage.
Code-highlightingon the Spot Syntax HighlightingCode Completion and suggestingremote compile Capabilities to my linux boxjump to line with erroreven a remote Visual debugger
Plus lots more goodies.
THIS A Story NOT A Traditional Tutorial - The Codes Thereness. But if you are: sit back with a packet of chips and plenty of caffeine. And enjoy ....
The Plan
No-one wants to re-invent the wheel. The whole point of OOP (Object oriented programming) is the reusability of objects. The whole point of the Internet was the reusability of someone else's object. Luckily I had read enough about these component " "to want to find some more. so i connection" shopping ".
My Shopping List:
Internet Controls (Telnet, Remote Shell, Remote Execute, FTP) Editor With Multi-File Capabilitiesysyntax Highlighter or Parserautomatic Syntax Highlighting
I shopped at:
Delphi Super PageTorri's PageborlandRxlib'srzlib'squickReport HomePage
Within 4 hour I was off the net with a number of goodies, 23 or so assorted controls, programs and Internet suites, (and plenty of stuff that had nothing to do with the current project, but I thought might be of use on my next . one) Eventually I whittled the choices down to: YourPasEditby DC AL CODA, Ken Hale and Coda HalePasToRTFby Martin Waldenburg (included in above) TntClientby Francois Piette (and associated ICS suite) RxToolsby those great Russian dudes.
YourPaseDit Was a Great Find, And ITS Description Said IT:
There are three main features in YourPasEdit. First is the PAS to RTF conversion unit, contained in mwPasToRtf.pas, by Martin Waldenburg. The second shows how to create TabSheets at run time, with a RichEdit. The third are the procedures written by Andrius Adamonis, Which Allow YourPasedit To BE Associated with Files and To Open Those Files in the Running Instance of YourPasedit, Creating a New Tabsheet and Richedit for the Newly Opened File.
Unfortunately IT Also Told Me:
IT IS Not Intended to Be A Full Delphi File Editor, Because It Does Not Highlight Keywords on The Fly, Like A Syntax Aware Editor.
But I was not complaining - I needed some challenge -!. Otherwise it would not be any fun So I delved into how things were being done in YourPasEdit To get the best from the following sections you should get your hands on at least YourPasEdit SO You Can Follow and (more importantly) Program Along.
Syntax highlight (YourPaseDit)
In YourPasEdit, syntax highlighting was done by parsing the plain text file, dividing each line of text into separate "Tokens", working out what TokenType each token was, and formatting them based on preset Font and Color settings. The following tokens were supported, corresponding to the Token types in the Delphi 3.0 Editor: TTokenState = (tsAssembler, tsComment, tsCRLF, tsDirective, tsIdentifier, tsKeyWord, tsNumber, tsSpace, tsString, tsSymbol, tsUnknown); How these tokens were formatted (that is with what Color and Attributes ) WAS determined by Using the delphi 3.0 Editors OWN Settings as the isy. Basically a line of pascal source such as:
Procedure TFORM1.FormCreate (Sender: Tobject); {Create the form}