INTERFACE ve IMPLEMENTATION'daki USES'lerin farkı nedir?

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
cengaver
Üye
Mesajlar: 111
Kayıt: 01 Nis 2014 05:02
Konum: İstanbul

INTERFACE ve IMPLEMENTATION'daki USES'lerin farkı nedir?

Mesaj gönderen cengaver »

Arkadaşlar,

interface kısmındaki USES ile implementation kısmındaki USES'in temel farkı nedir? Neden böyle bir ayrım var? Yani tek bir uses ile bu işi halledebilecekken neden her iki bölümde de bu uses'ler tanımlanabiliyor temel farkı nedir?
xxxjedixxx
Üye
Mesajlar: 216
Kayıt: 10 Ara 2013 03:50

Re: INTERFACE ve IMPLEMENTATION'daki USES'lerin farkı nedir?

Mesaj gönderen xxxjedixxx »

Örnek vereyim. İki tane formumuzun olduğunu düşün ve adları da Form1 ve Form2 olsun. Form1'in ünitesi Unit1 ve Form2'nin ünitesi Unit2 olsun.
Form1 içindeki bir kod ile Form2'ye ait bir kodu çağıralım. Önce Uses'a Form2'yi eklememiz gerekir. Eklerken interface bölümündeki yani en üstteki uses'a Unit2'yi yazabiliriz. Bunda bir sorun yok. Fakat Form2'den de Form1'e ait bir kodu çağırmak istediğimizde bu sefer Unit1'i en üstteki yani interface bölümündeki uses'a yazamayız. Compiler bize hemen "Circular unit reference to 'Unit1'" şeklinde mesaj verecektir. Bunun sebebi compiler'ın unit1'i derlerken üstteki uses kısmında unit2'yi gördüğü için unit2'yi de derlemeye gidecektir. Bu sefer unit2'ye girdiğinde de yukarıdaki uses'daki unit1 gördüğü için tekrar unit1'e gidecektir. Bu durumda sonsuz bir döngü oluştuğu için buna izin vermemektedir. Bu yüzden bu durumun oluşmaması için Delphi implemetation bölümündeki yani alttaki uses'ı kullandırmaktadır.

Delphi 7'nin yardımındaki açıklamayı aynen kopyalıyorum.
One or more units use each other in their interface parts.
As the compiler has to translate the interface part of a unit before any other unit can use it, the compiler must be able to find a compilation order for the interface parts of the units.
Check whether all the units in the uses clauses are really necessary, and whether some can be moved to the implementation part of a unit instead.

unit A;
interface
uses B; (*A uses B, and B uses A*)
implementation
end.

unit B;
interface
uses A;
implementation
end.

The problem is caused because A and B use each other in their interface sections.

unit A;
interface
uses B; (*Compilation order: B.interface, A, B.implementation*)
implementation
end.

unit B;
interface
implementation
uses A; (*Moved to the implementation part*)
end.

You can break the cycle by moving one or more uses to the implementation part.
En son xxxjedixxx tarafından 22 May 2014 04:09 tarihinde düzenlendi, toplamda 1 kere düzenlendi.
Kullanıcı avatarı
cengaver
Üye
Mesajlar: 111
Kayıt: 01 Nis 2014 05:02
Konum: İstanbul

Re: INTERFACE ve IMPLEMENTATION'daki USES'lerin farkı nedir?

Mesaj gönderen cengaver »

Teşekkür ederim.
xxxjedixxx
Üye
Mesajlar: 216
Kayıt: 10 Ara 2013 03:50

Re: INTERFACE ve IMPLEMENTATION'daki USES'lerin farkı nedir?

Mesaj gönderen xxxjedixxx »

Rica ederim.
Cevapla