【问题标题】:Uses clause index in source code在源代码中使用子句索引
【发布时间】:2018-02-15 06:19:58
【问题描述】:

我不知道为什么我应该把uses子句放在哪里以及为什么要放在哪里。

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.

另外,使用单元的第一优先级是什么?为什么 winapi.windows 总是排在第一位,如果不是排在第一位会怎样?

【问题讨论】:

标签: delphi


【解决方案1】:

Help 告诉我们:

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

作为第二个原因的示例 - 尝试将 Graphics 放在 Windows 单元之前并使用 TBitmap

【讨论】:

    猜你喜欢
    • 2011-12-09
    • 2014-06-08
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2015-07-30
    • 2016-09-30
    • 1970-01-01
    相关资源
    最近更新 更多