Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use "System.SysUtils" or "SysUtils" in Delphi?

Tags:

delphi

In Delphi XE3, it seems that one can use either "System.SysUtils" or "SysUtils", "Vcl.FileCtrl" or "FileCtrl".

I read the article in http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/usingnamespaces_xml.html , it seems the former is called full qualified namespace, while the latter is the generic name. But if i understand correct, one should add statements like:

"Uses System, Vcl", before one can use the units under these namespaces. But I check the codes but cannot find any "Uses System" or "Uses vcl". Why?

like image 832
alancc Avatar asked Oct 09 '19 02:10

alancc


Video Answer


1 Answers

You are reading old documentation, and reading the wrong topic anyway.

System and Vcl in this context are actually Unit Scope Names, which are similar to, but quite different from, Namespaces. Unit Scope Names were introduced in XE2, to allow VCL and FMX to share common unit names under different scopes (Vcl.Forms vs FMX.Forms, etc). Existing VCL code being migrated to FMX did not (largely) need to be re-written, it could use just Forms, etc and magically pick up the correct scope based on project type. The same does not work with Namespaces.

The reason you don't have to explicitly specify Unit Scope Names in uses statements in code is because they are configured at the project level instead, and by default most VCL projects have the System and Vcl scope names pre-configured.

So, when you use just SysUtils, FileCtrl etc in your code, the compiler checks them against the project's Unit Scope Names and eventually finds System.SysUtils, Vcl.FileCtrl, etc.

like image 81
Remy Lebeau Avatar answered Oct 16 '22 15:10

Remy Lebeau