在源代码中使用子句索引

Bia*_*nca 0 delphi

我永远不知道在何处以及为什么我应该使用条款的原因是什么.

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs; // why put on top ?

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

uses  System.Math, System.IOUtils, System.WideStrUtils; // why put here ?

procedure TForm2.FormCreate(Sender: TObject);
begin
  //
end;

end.
Run Code Online (Sandbox Code Playgroud)

另外,使用单位的首要任务是什么?为什么winapi.windows总是排在第一位,如果不是第一名会发生什么?

MBo*_*MBo 9

帮助告诉我们:

单位出现在uses子句中的顺序决定了它们的初始化顺序,并影响编译器定位标识符的方式.如果两个单元声明了具有相同名称的变量,常量,类型,过程或函数,则编译器将使用uses子句中最后列出的单元中的一个.

作为第二个原因的例子 - 尝试Graphics在Windows单位之前放置并使用TBitmap