8

I'm trying to use the TDRecLst and TDSplyCm units from the code included with The Tomes of Delphi, but I get a compiler error in TDBasics.pas:

Identifier expected but 'CONST' found

I get a similar error in TDStrRes.inc:

Same error as above

What's wrong, and how do I fix it?

The code is available from the author.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
tbutton
  • 111
  • 6
  • 1
    I think the question is very good. The poster "can't compile the program and don't understand why". What more do you need? Any additional information may bias the possible responses. Anyway, 10 against 1 it is a search path/unit not found issue. For example, to compile TDRecList.pas, files TDBasics.pas and TDDefine.inc have to be present in the search path. – Igor Jun 05 '13 at 20:54
  • Igor, thank you! I don't understand too... There is unit (see the link at my post). I add the unit in program. Is it clear? I can't compile the code. Errors: http://i.stack.imgur.com/VIM6x.png http://i.stack.imgur.com/7i3To.png – tbutton Jun 05 '13 at 21:13
  • 2
    @Igor, you're correct that more information would bias the responses; it would bias them toward being *helpful* instead of just shots in the dark. The most basic piece of missing information in this question is the *error message*. – Rob Kennedy Jun 05 '13 at 21:15
  • In the previous question you were missing units. Is this question different? Did you now download all the source units? – David Heffernan Jun 05 '13 at 21:24
  • 2
    @David, it's now clear to me what the problem is: Despite being updated in 2005, the code is only prepared to detect Delphi versions up to 6 (VER140). When TDDefine.inc doesn't detect a version, code elsewhere ends up missing key parts (like the units in a `uses` clause). – Rob Kennedy Jun 05 '13 at 21:29
  • @Rob That would explain why I had no trouble compiling in my legacy Delphi which is D6. – David Heffernan Jun 05 '13 at 21:36
  • Screenshots for compiler messages ... phew! – undur_gongor Jun 05 '13 at 21:47
  • Thank you for editing your question which turned it from some -5 votes to +8. – Jerry Dodge Jun 06 '13 at 23:06

1 Answers1

13

You're evidently using a Delphi version that's newer than Delphi 6. Despite being updated in 2005, the code from that book only detects up to that version of Delphi. TDDefine.inc defines a number of compiler symbols based on the version it detects, but when the version you're using isn't anything it recognizes, it defines no symbols. That eventually leads to problems later when the compiler encounters code like this in TDBasics.pas;

implementation

uses
  {$IFDEF Delphi1}
  WinTypes, WinProcs;
  {$ENDIF}
  {$IFDEF Delphi2Plus}
  Windows;
  {$ENDIF}
  {$IFDEF Kylix1Plus}
  Types, Libc;
  {$ENDIF}

{$IFDEF Delphi1}
{$R TDStrRes.r16}
{$ENDIF}
{$IFDEF Delphi2Plus}
{$R TDStrRes.r32}
{$ENDIF}
{$IFDEF Kylix1Plus}
{$R TDStrRes.r32}
{$ENDIF}

const
  UnitName = 'TDBasics';

Since none of Delphi1, Delphi2Plus, or Kylix1Plus is defined, the uses clause is empty. When we ignore all the compiler directives and inactive code blocks, the compiler ultimately sees code like this:

implementation

uses

const
  UnitName = 'TDBasics';

That's why the compiler complains about expecting an identifier instead of const.

To fix it, you need to teach TDDefine.inc to recognize your version of Delphi. Easier, though, might be to ignore all the version-detection code and hard-code all the symbols that apply to the version you're using. As long as you never use any version older than Delphi 6, all the symbols will apply to all your versions.

Find the following block of code in TDDefine.pas:

{$IFDEF VER140}
  {$DEFINE Delphi6}
  {$DEFINE Delphi1Plus}
  {$DEFINE Delphi2Plus}
  {$DEFINE Delphi3Plus}
  {$DEFINE Delphi4Plus}
  {$DEFINE Delphi5Plus}
  {$DEFINE Delphi6Plus}
  {$DEFINE HasAssert}
{$ENDIF}

Remove the first and last lines so that the remaining $DEFINE instructions are processed unconditionally.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Thank you! To solve the problem to add {$IFDEF VER150 } {$DEFINE Delphi7} {$DEFINE Delphi1Plus} {$DEFINE Delphi2Plus} {$DEFINE Delphi3Plus} {$DEFINE Delphi4Plus} {$DEFINE Delphi5Plus} {$DEFINE Delphi6Plus} {$DEFINE HasAssert} {$ENDIF} in TDDefine.inc (Delphi 7) – tbutton Jun 06 '13 at 18:45
  • But what should we add for Delphi XE or XE4 ? – tbutton Jun 06 '13 at 18:49
  • Who cares? The rest of the book's code never checks any additional Delphi versions, so why bother adding lines and lines of code to detect them? If you really must know, check the [complete list of defines for Delphi versions](http://stackoverflow.com/q/750801/33732), and then adapt your code to use the symbols defined there instead of the symbols the book's author chose. – Rob Kennedy Jun 06 '13 at 20:22