Creating different mapping resources for TadVT100Emulator.
The TAdCharSetMapping and TAdKeyboardMapping classes get their initial mapping tables from an application resource. These resources, one for each type of mapping class, come from resource files, the first being called ADCHSVT1.R32 (or .R16 in 16-bit), the second ADTRMVT1.R32 (or .R16). These resource files are compiled using Delphi’s BRCC or BRCC32 from a resource script: the one for the charset mapping is called ADCHSVT1.RC, the one for the keyboard mapping is called ADTRMVT1.RC.
Let’s look at and discuss the script for the keyboard mapping (the arguments we make will apply just as well to the charset mapping resource), and see how we can change the mapping table.
If you look at ADTRMVT1.RC, you’ll see that it contains just one line that can be compiled:
ADVT100KeyMap RCDATA ADTRMVT1.BIN
To the resource compiler this statement means the following: create a resource file containing a resource named ‘ADVT100KeyMap’. This resource is of the RCDATA type (essentially a binary block of data). The data for the resource can be found in a file called ‘ADTRMVT1.BIN’. We provide ADTRMVT1.BIN with APRO 3, but where did we get it? This article talks about how to change this mystery file so that you can link in a different keyboard mapping table (or, indeed, a charset mapping table) to your application.
The first point to realize is that the mappings used by the terminal family of classes were originally written as text files. The text files we provide with APRO 3 are ADCHSVT1.TXT (the charset mappings) and ADTRMVT1.TXT (the keyboard mapping). These text files have a very simple format, providing just enough flexibility to be able to succinctly describe a mapping table. You can create your own mapping text files from these standard ones and get the mapping objects to read them in at run-time by calling their LoadFromFile methods. At that point, you’ll have changed the behavior of the mapping objects.
However, this does mean that your application has to ship with these extra files. Even worse, they’re simple text files and, as such, might encourage certain users to experiment changing them, perhaps causing some problems with your application. It would be far better to be able to compile the mapping tables directly into your application via resources using these mysterious BIN files.
Each of the mapping classes has a StoreToBinFile method. This method was expressly written to create the BIN files that are compiled into the resource files.
The plan of attack goes like this. Create a new application. Drop two edit controls and a button onto the form. The first edit control will be used to specify the mapping table text file name, the second to specify the BIN file name that will be ‘compiled’ from the text file.
Double click on the button, and write the following code for the OnClick event handler:
MyMapper : TAdKeyboardMapping;
MyMapper := TAdKeyboardMapping.Create;
(Note: you will have to add AdTrmMap to the uses list for the unit, so that the compiler can find the TAdKeyboardMapping class.)
The code is very simple: we create a keyboard mapping object, load a mapping table from the text file defined by the first edit control, and then immediately write this mapping table out as a BIN file whose name is provided by the second edit control. Free the mapping object and we’re done.
Obviously, you can make the application easier to use and more robust by adding file browser components and extra error checking, but this article is designed to illustrate the basic steps.
Using this binary file (renaming it to ADTRMVT1.BIN, if necessary), you can compile the resource script file to a resource, link the resource file into your application and have a different keyboard mapping than we provide. You can even leave the standard mapping table in your application and link in a separate one containing your own mapping table—just create your own RC file to compile in your BIN file created by the above program. You will have to give the resource a different name from the standard ADVT100KeyMap name, of course, since all resources in an application must have different names.
To get the VT100 emulator’s keyboard mapping object to recognize this new mapping table you would add the following code to your application prior to using the terminal and VT100 emulator:
Where MyVT100Emulator is the name of the VT100 emulator component you are using, and ‘MyResName’ is the name of the resource you have created.
This site is not affiliated, endorsed, or otherwise associated with the
entity formerly known as
TurboPower Software. The owners and maintainers of Aprozilla.com were merely
meager employees of the aforementioned organization, providing this site out of
the pure goodness of their collective hearts.