Recent

Author Topic: Text-file device driver set but not invoked  (Read 2578 times)

wnelis

  • Newbie
  • Posts: 3
Text-file device driver set but not invoked
« on: May 26, 2015, 02:50:06 pm »
I am stuck on a problem. A text-file device driver is set by invoking the appropriate Assign-procedure, but the associated InOut function is never called.

Background: A legacy application is initially written in TP7 and uses unit Crt. Later on it is ported to D6, and unit Crt is replaced by unit Console, written by Rudolph Velthuis. Now I am porting the application, named pgit, to Lazarus 1.4.0 under Windows 8.1.

Application pgit uses line-drawing characters, which require an appropriate code page to be set and an appropriate font to be chosen. Neither unit Console nor unit CRT, from FPC, work correctly. The line-drawing characters are (for a part) a problem, while unit Crt does not position the second and following lines in a window correctly. Unit Console is adapted to handle UTF-8 characters, and the text-file device driver of unit Crt is now used in unit Console too. In a small test program, it can be shown that the new version of Console does work as expected: the line-drawing characters are shown as intended and the text is positioned correctly in the window. However, when used in application pgit, it does not work.

Using breakpoints it is shown that the AssignCrt procedure is invoked (from the initialization section of unit Console). It is not invoked from any other part of application pgit.  A break point on the InOut function of this driver does not trigger, thus the InOut function is never invoked. (The same test in the aforementioned test program does trigger the break point in the inOut function.) It seems that the default driver is used to write to the console, rather than the InOut function defined in unit Console.

Note: application pgit uses four other text-file device drivers as well. There is one to read the command line like a file, one to build a file in the heap, one to distribute logging messages to multiple destinations and one to read a file from an archive.

I have no idea any more on how to proceed to understand this problem. Are there any ideas on how to find out what is going wrong? Or better: are there any ideas on what might be wrong?

wnelis

  • Newbie
  • Posts: 3
Re: Text-file device driver set but not invoked
« Reply #1 on: May 30, 2015, 12:38:52 pm »
The initialization sections of the units of a program are invoked in an order defined by the compiler. How can I see in which order the units are initialized? How can I change the order of initialization?

wnelis

  • Newbie
  • Posts: 3
Re: Text-file device driver set but not invoked
« Reply #2 on: May 30, 2015, 02:24:14 pm »
The original problem is solved: unit Console is now the last unit mentioned in the uses-clause of the main program, causing its initialization section to be the last one to be executed. After this minor modification, writing UTF-8 to the console works as expected.

My guess is that one of the other units invokes another unit, possibly one supplied with FPC, which assigns standard input and standard output too, causing the assignment in the initialization of unit Console to be undone.
 

 

TinyPortal © 2005-2018