Question about $include lazarus / 21-General ---------------------------------------------------------------------- ydd · 2021-01-17 03:16 documentation: https://wiki.freepascal.org/$include I have unit "SomeVeryLongUnitName" and I want to include: "SomeVeryLongUnitName_RT" so I need to use: {$include SomeVeryLongUnitName_RT} but there is special tag %file%:   {$include %file%} expands to the file’s name the directive is found in How I can use something like:   {$include %file%_RT} ? ---------------------------------------------------------------------- MarkMLl · 2021-01-17 09:37 Curious: I don't see mention of the include directive in the official documentation at https://www.freepascal.org/docs- html/current/prog/prog.html It does however document $includepath, but I'm not sure that will help I suspect that it's not possible to do what you want without using an external program as a preprocessor, one of the problems is that  $I %file%  expands as a quoted string so even if the expansion worked it wouldn't be quite as expected. MarkMLl ---------------------------------------------------------------------- lucamar · 2021-01-17 11:30 Quote from: MarkMLl on January 17, 2021, 10:37:48 amCurious: I don't see mention of the include directive in the official documentation at https://www.freepascal.org/docs-html/current/prog/prog.html Huh? It's there all right ... (see attached image) As for the OP's question, no it can not be used that way; {$I %somevar%} inserts a string constant in the source, which is not what you want. ---------------------------------------------------------------------- MarkMLl · 2021-01-17 12:05 Quote from: lucamar on January 17, 2021, 12:30:42 pmQuote from: MarkMLl on January 17, 2021, 10:37:48 amCurious: I don't see mention of the include directive in the official documentation at https://www.freepascal.org/docs-html/current/prog/prog.html Huh? It's there all right ... (see attached image) As for the OP's question, no it can not be used that way; {$I %somevar%} inserts a string constant in the source, which is not what you want. Well, I did say it was curious... I'd been peering at that page and I'm sure I tried a search and for some reason couldn't see it (and yes, I do know there's two lists on the page). If I had been able to see it I might have been a bit less guarded in pointing out the distinction between definitive documentation and apocrypha in the wiki, which is something I had to come to terms with many years ago when dealing with both Microsoft and Microsoft Press and discussing things like the Petzold books (published by the latter, hence not acknowledged as documentation by the former). MarkMLl ---------------------------------------------------------------------- PascalDragon · 2021-01-17 16:10 Quote from: ydd on January 17, 2021, 04:16:25 amHow I can use something like:   {$include %file%_RT} You can't. Simple as that. ---------------------------------------------------------------------- MarkMLl · 2021-01-17 16:40 Quote from: PascalDragon on January 17, 2021, 05:10:24 pmYou can't. Simple as that. Can you see any way round it? For example, can . be knocked out of the include path so that the include file could be in a subdirectory? OP, tell us what you're trying to do and why the name can't be hardcoded. MarkMLl ---------------------------------------------------------------------- Kays · 2021-01-17 16:57 Quote from: MarkMLl on January 17, 2021, 05:40:25 pm[…] Can you see any way round it?You can do something else. You can utilize the {$include *} directive. If you check out compiler/scanner.pas, you see only the file suffix (usually separated by a dot) is preserved. So (if you can change the file name patterns) how about writing something like: Code: [Select]$ head foo.pas foo.RT ==> foo.pas <== program foo(output); begin         writeLn({$include *.RT}); end. ==> foo.RT <== 'Abracadabra' If you aren’t allowed to change the file name, you may utilize a (symbolic) link foo.RT→foo_RT. ---------------------------------------------------------------------- MarkMLl · 2021-01-17 18:08 Quote from: Kays on January 17, 2021, 05:57:23 pmYou can do something else. You can utilize the {$include *} directive. That has some interesting possibilities, but I can see it interacting badly with the possible unit name issues I raised a few days ago https ://forum.lazarus.freepascal.org/index.php/topic,52884.msg390815.html MarkMLl ---------------------------------------------------------------------- ydd · 2021-01-17 23:24 Quote from: Kays on January 17, 2021, 05:57:23 pmYou can do something else. You can utilize the {$include *} directive it works for me, I can use: {$I *.RT} - for file with name: SomeVeryLongUnitName.RT but I cannot use like this: {$I *.RT.pas} - for file with name: SomeVeryLongUnitName.RT.pas error - Fatal: Syntax error, "BEGIN" expected but "UNIT" found ---------------------------------------------------------------------- Kays · 2021-01-17 23:45 Quote from: ydd on January 18, 2021, 12:24:17 am[…] I cannot use like this: {$I *.RT.pas} […]No, this won’t work, this notation only allows you to specify a single possibly non-standard (file type hint) suffix. It’s not replace and concatenate. You would’ve seen that if you took a look at source code lines I referenced above. Earlier today I’ve expanded the wiki page on that pointing out just that. You still can create a symbolic link foo.RT→foo.RT.pas, but it’s a cumbersome solution relying on file system capabilities. Also, AFAIK SCMs like the popular git(1) won’t adequately manage them. (Or was it just hard links that won’t be preserved? Anyway, it’s inconvenient.)