Use “System.SysUtils” or “SysUtils” in Delphi?

孤人 提交于 2020-05-29 02:59:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/58296417/use-system-sysutils-or-sysutils-in-delphi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!