![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Зачем USES разбиты на два блока? [D6]
Darlock © (2002-10-09 18:10:00)Не подскажет ли кто зачем USES разнесены на два блока interface и implementation
Best Before 2024 (2002-10-09 18:41:00) [21]Что мне, весь Help прислать
From Help:
Object Pascal Language Guide
Multiple and indirect unit references
The order in which units appear in the uses clause determines the order of their initialization (see The initialization section
)and affects the way identifiers are located by the compiler. If two units declare a variable, constant, type, procedure, or function with the same name, the compiler uses the one from the unit listed last in the uses clause. (To access the identifier from the other unit, you would have to add a qualifier: UnitName.Identifier.)
A uses clause need include only units used directly by the program or unit in which the clause appears. That is, if unit A references constants, types, variables, procedures, or functions that are declared in unit B, then A must use B explicitly. If B in turn references identifiers from unit C, then A is indirectly dependent on C; in this case, C needn’t be included in a uses clause in A, but the compiler must still be able to find both B and C in order to process A.
The example below illustrates indirect dependency.
program Prog;
uses Unit2;
const a = b;
...
unit Unit2;
interface
uses Unit1;
const b = c;
...
unit Unit1;
interface
const c = 1;
...
In this example, Prog depends directly on Unit2, which depends directly on Unit1. Hence Prog is indirectly dependent on Unit1. Because Unit1 does not appear in Prog’s uses clause, identifiers declared in Unit1 are not available to Prog.
still (2002-10-09 18:37:00) [22]
> Best Before 2024 (09.10.02 18:34)
ну ок, с этим ясно. а вот с моим вопросом тоже может просветишь?
> допустим, есть unit a
> unit b interface uses a
> unit c interface uses b
>
> Но то, что у а в интерфейсе, в unit c не видно!
Best Before 2024 (2002-10-09 18:34:00) [23]From Help:
Object Pascal Language Guide
Multiple and indirect unit references
...To compile a client module, the compiler needs to locate all units that the client depends on, directly or indirectly. Unless the source code for these units has changed, however, the compiler needs only their .dcu (Windows) or .dcu/.dpu (Linux) files, not their source (.pas) files.
When changes are made in the interface section of a unit, other units that depend on it must be recompiled. But when changes are made only in the implementation or other sections of a unit, dependent units don’t have to be recompiled. The compiler tracks these dependencies automatically and recompiles units only when necessary.
Darlock (2002-10-09 18:33:00) [24]2Best Before 2024
interface = intf
implementation = impl
На самом деле если я uses модуль в intf - то я могу пользовать его состав как в intf своего модуля так и в impl. Но если я его uses в impl, то могу пользовать только в impl своего модуля. Зачем тогда (кроме реализации цикличности) мне что-то uses в impl, если я могу жто uses только intf?
Я надеюсь не сильно замутил... :)
Best Before 2024 (2002-10-09 18:28:00) [25]в interface uses те модули, которые нужны для объявления переменных в этой секции в implementation - те, которые нужны для реализации, но их нет в interface
still (2002-10-09 18:27:00) [26]вообще говоря, конечно неправильный
Darlock (2002-10-09 18:24:00) [27]2Best Before & 2andrey_pst
Ответы супер... т.е. когда я пишу в interface uses unit1. - это я его описываю, а когда в implementation - это я его реализовую... Ничего странного не находите? :)
2Still Про цекличность я знал, но считал что это не правельный стиль программирования...
still (2002-10-09 18:16:00) [28]например, если требуется организовать циклическую ссылку (ну бывает такая неоходимость). Например, unit a должен видеть unit b и наоборот
то в interface у unita a прописываем uses b, а в implementation у unit b - uses a иначе компилятор ругается
Мне вот чего непонятно -
допустим, есть unit a
unit b interface uses a
unit c interface uses b
Но то, что у а в интерфейсе, в unit c не видно! вот это почему так сделано - непонятно.
Best Before 2024 (2002-10-09 18:13:00) [29]Затем же зачем и программа разделена на эти секции
andrey_pst (2002-10-09 18:13:00) [30]interface - описание
implementation - реализация
Книги по Pascal почитайте.