Missing WEBLIB define in new WebCore projects?

Is it a bug or feature that the "WEBLIB" define is missing from the project settings when you create a new "TMS Web Application" project?
Apparently, some parts of the library compile quite differently if that define is not set.


Nothing changed in this area.
WEBLIB is defined in {$I WEBLib.TMSWEBDefines.inc}
It is present there, so under TMS WEB Core all units that use it are compiled correct.

Hi Bruno, thanks for following up!

I'm trying to understand what going on. I came to that missing define while experimenting with TTMSFNCStylesManager, which didn't seem to work as advertised.

To understand how it works, I walked through the sources and found this:
Bildschirmfoto 2023-07-25 um 12.35.42

This is in D11, so you can easily spot that WEBLIBis /not/ defined here, which is why I set WEBLIB on project level, which seems that it makes things work correctly.

Following your hint about TMSWEBDefines, I found that there are actually two versions of that include file:
One in C:\Projekte\TMS\TMS WEB Core RSXE14\Core Source
and the other one in C:\Projekte\TMS\TMS WEB Core RSXE14\Component Library Source
These two versions are different though. The first one defines "WEBLIB", the one in "Component Library Source" does not - which makes sense, as at design time we are technically not in "Web mode", but in VCL mode.

Now here comes the final resolution:
Only" C:\Projekte\TMS\TMS WEB Core RSXE14\Component Library Source" was in my Library Search path, so the compiler only found the include that does not define WEBLIB.

I have no idea if I made a mistake during installation. I now added "C:\Projekte\TMS\TMS WEB Core RSXE14\Core Source" to the library path (before "Component Library Source"), and it seems the styles manager works correctly.

The question is now:
What happens if I wanted to recompile the components? They would pick the wrong include file, I guess ...

That is why I am wondering if it would be more stable to set the "project type define" (i.e. WEBLIB here) on project-level. That way you always know exactly what we are compiling for and don't have to make guesses, depending on different paths ...


For runtime, TMS WEB Core always compiles with files under "Core Source" , so as expected and as by design, WEBLIB is defined in TMSWEBDefines.inc
There should be no design-time folder included in the TMS WEB Core library path. So, if somehow, these paths were added, please remove.

Apparently, things are more complicated. Take a look at TTMSFNCStylesManager, as it is declared in:

It offers two extra methods in WEBLIB mode:

procedure LoadStyleFromURL(AURL: string; AComponents: TTMSFNCStylesManagerComponentArray); overload; virtual;

procedure LoadStyleFromURL(AURL: string); overload; virtual;

But WEBLIB is NOT defined in VCL.TMSFNCStyles.pas. It only includes {$I VCL.TMSFNCDefines.inc} from the FNC source, which does NOT define WEBLIB.

In other words: LoadStyleFromURL is NOT available in TMS WEB Core apps - unless you define WEBLIB in project settings.

I might still be missing something here, but I am trying to understand the mechanics :slight_smile:

There are other places in the code where the WEBLIB define is questionable, but this one example is easy to follow...

LoadStyleFromURL is available in TMS WEB Core.
The only issue I can see is that LoadStyleFromURL is not available in auto-completion when using it in a TMS WEB Core project. But it is available and you can use it.

The reason here is that the TMS WEB Core form designer is a VCL form designer and thus, at design-time, for FNC , the components behaves as a VCL component and auto-completion is based on the VCL interface.

As long as the form designer will need the VCL variant of the control, I see no workaround for this shortcoming unfortunately.

I am not talking about code completion but about compilation issues. In the source as it comes with FNC Core (as of 06.07.2023), "TMSFNCStylesManager1.LoadStyleFromURL()" is not available because it is ifdef'ed with WEBLIB, which is NOT defined in that unit (and in none of its include files).

Let me rephrase my actual question:
How would FNC components or their source detect that they are used within a Web Core project if there is no WEBLIB define on project level (which, apparently, is not by default)?

(Or same question: how would FNC detect that it is currently compiling for VCL or FMX?)

I really want to understand this to not break things :)

I believe I found the theoretical answers to my questions:

For each platform (Web, FMX and VCL) there is a "wrapper" unit/component for every component:

TTMSFNCEdit comes in three units:

  • FMX.TMSFNCEdit.pas
  • VCL.TMSFNCEdit.pas
  • WEBLib.TMSFNCEdit.pas

Each of these units comes with its platform-specific implementation and include files. So far so good.

This is my source as it is created when I choose "TMS Web Application" from the wizard and add an FNCEdit to its form (I only changed the line breaks for better readability):

unit Unit184;


  System.SysUtils, System.Classes,

  JS, Web,

  WEBLib.Graphics, WEBLib.Controls, WEBLib.Forms, WEBLib.Dialogs,

  Vcl.Controls, Vcl.StdCtrls, Vcl.TMSFNCEdit;

  TForm184 = class(TWebForm)

It uses the VCL variant of TMSFNCEdit.pas, and thus it behaves as VCL component. As long, as there is no direct dependency on WEBLIB, this probably works due to some magic in the WebCore compiler, but in the StylesManager there is something missing ...

I understand that the IDE only knows about FMX and VCL, thus you have to build components/applications on either of these, and you obviously decided to use VCL for WEB Core apps.

This again, leads to the question: How does Vcl.TMSFNCEdit.pas know if it is currently compiling for VCL or WEB Core?

  1. The TMS WEB Core compiler ensures the WebLib.TMSFNCEdit.pas unit is used to compile against (even when VCL.TMSFNCEdit is specified in the uses list)
  2. In WebLib.TMSFNCStyles.pas, there is {$I WEBLib.TMSFNCDefines.inc} and this .INC file defines WEBLib
  3. Finally, I retested this and the code:
procedure TForm1.WebFormCreate(Sender: TObject);
  sm: TTMSFNCStylesManager;
  sm := TTMSFNCStylesManager.Create(Self);

compiles fine in a TMS WEB Core app.
Project1.zip (5.2 KB)

Thanks for the demo!

You used TTMSFNCStylesManager manually, directly from WEBLib.TMSFNCStyles, which has the include/defines as you explained. That is straightforward, with no issues.

I dropped a StylesManager component onto the form in the IDE, which will instead add VCL.TMSFNCStyles to the uses - which made me stumble about the then missing WEBLib define.

I think I understand everything now:

  1. that missing define only causes code completion issues (I had a situation where the compiler threw an error, but I cannot reproduce that anymore. I might have gotten confused at some point)

  2. If the project is a WebCore project, then the Web Core compiler internally sets the WEBLib define and makes sure the code gets compiled as designed - even if you use any of the VCL.TMSFNCxyz units.

  3. The code completion issue can be worked around by setting a WebLib define on project level - that satisfies the LSP.

Thank you very much for being patient with me :-)

1 Like