Konuyu Oyla:
  • Derecelendirme: 5/5 - 3 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Fonksiyon ve Method Tipleri
#1
Pointer Tipleri:
Bilindiği üzere pointer tipleri; 32 bit platformda 4 byte (32 bit) alan kaplar.64 bit platformada ise 8 byte (64 bit) alan kaplar.

Procedürel Tipler:
32 bit platformda fonksiyon ya da procedure pointer'ı 4 byte (32 bit) alan kaplar.Bir method pointer ise yine 4 byte(32 bit) yer kaplar.Devamında ise 4 byte'lık nesnenin pointerı bulunur.
64 bit platformda fonksiyon ya da procedure pointer'ı 8 byte (64 bit) alan kaplar.Bir method pointer ise yine 8 byte(64 bit) yer kaplar.Devamında ise 8 byte'lık nesnenin pointerı bulunur.

Yukarıdaki açıklamalarda bahsedilen method yapısı System.pas ya da System.hpp uniti içerisinde bulunan TMethod record yapısı ile ifade edilir.
Record'un yapısına bakmaya üşenen programcılar için amme hizmeti;
Delphi
  PMethod = ^TMethod;
 TMethod = record
   Code, Data: Pointer;
 public
   class operator Equal(const Left, Right: TMethod): Boolean; inline;
   class operator NotEqual(const Left, Right: TMethod): Boolean; inline;
   class operator GreaterThan(const Left, Right: TMethod): Boolean; inline;
   class operator GreaterThanOrEqual(const Left, Right: TMethod): Boolean; inline;
   class operator LessThan(const Left, Right: TMethod): Boolean; inline;
   class operator LessThanOrEqual(const Left, Right: TMethod): Boolean; inline;
 end;

C++
typedef TMethod *PMethod;
struct DECLSPEC_DRECORD TMethod
{
public:
void *Code;
void *Data;
static bool __fastcall _op_Equality(const TMethod &Left, const TMethod &Right);
static bool __fastcall _op_Inequality(const TMethod &Left, const TMethod &Right);
static bool __fastcall _op_GreaterThan(const TMethod &Left, const TMethod &Right);
static bool __fastcall _op_GreaterThanOrEqual(const TMethod &Left, const TMethod &Right);
static bool __fastcall _op_LessThan(const TMethod &Left, const TMethod &Right);
static bool __fastcall _op_LessThanOrEqual(const TMethod &Left, const TMethod &Right);
};

TMethod.Code alanında fonksiyon ya da procedure'nin adresi saklanır.
TMethod.Data alanında nesnenin adresi saklanır.

Fonksiyon tiplerine örnek:
Delphi
type 
 THesapla1 = function(X, Y: Integer): Integer;              // 32 bit platformda 4 byte, 64 bit platformda 8 byte yer kaplar.
 THesapla2 = function(X, Y: Integer): Integer of object; // 32 bit platformda 8 byte, 64 bit platformda 16 byte yer kaplar.Yukarıda TMethod yapısı ile ifade edildiğinden bahsedildi.

C++
  typedef int __fastcall (*THesapla1)(int X, int Y);
 typedef int __fastcall (__closure *THesapla2)(int X, int Y);

Sizeof ile kapladığı alana bakılabilir.
 ShowMessage(SizeOf(THesapla1).ToString());
ShowMessage(SizeOf(THesapla2).ToString());

Delphide ki "of object" ile C++ Builder'da ki __closure ifadesi aynı şeydir.

Şimdi kullanıma bakalım;
type
 THesapla1 = function(X, Y: Integer): Integer;

 THesapla2 = function(X, Y: Integer): Integer of object;

 THesapla = class
 public
   function Topla(X, Y: Integer): Integer;
   function Carp(X, Y: Integer): Integer;
   function Cikar(X, Y: Integer): Integer;
 end;

implementation

{$R *.dfm}

function Topla(X, Y: Integer): Integer;
begin
  Result := X + Y;
end;

function Carp(X, Y: Integer): Integer;
begin
  Result := X * Y;
end;

function Cikar(X, Y: Integer): Integer;
begin
  Result := X - Y;
end;

{ THesapla }
function THesapla.Carp(X, Y: Integer): Integer;
begin
  Result := X * Y;
end;

function THesapla.Cikar(X, Y: Integer): Integer;
begin
  Result := X - Y;
end;

function THesapla.Topla(X, Y: Integer): Integer;
begin
  Result := X + Y;
end;


var
 Hesapla: THesapla1;
 Sonuc: Integer;
begin
 Hesapla := Carp; // Topla; Carp; Cikar;
 Sonuc := Hesapla(3, 5);
 ShowMessage(Sonuc.ToString());
end;

var
 Hesapla: THesapla;
 Hesapla2 : THesapla2;
 Method: TMethod;
 Sonuc : Integer;
begin
 Hesapla := THesapla.Create;
 Method.Code := @THesapla.Topla;  // @THesapla.Topla; @THesapla.Topla; @THesapla.Topla;
 Method.Data := @Hesapla;
 Hesapla2 := THesapla2(Method);
 Sonuc := Hesapla2(3,5);
 ShowMessage(Sonuc.ToString());
 Hesapla.Free;
end;

Yanlış hatırlamıyorsam 64 bit platform desteği XE2 ile birlikte gelmişti.
WWW
Cevapla
#2
Güzel Konu Teşekkürler.
Yalnızım ama bir kente yürüyen ordu gibiyim, edebiyattan kaçınmalıyım..
Cevapla
#3
Ellerinize sağlık. 
Benzer makale serilerini bekliyoruz.
DelphiCan'dır!
Cevapla
#4
Fırsat buldukça yazmaya çalışacağım.
WWW
Cevapla
#5
Çok teşekkürler , yenilerini sabırsızlıkla bekliyor olacağım. Elinize sağlık.
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Delphi ile .Net Ortamında geliştirilen dll içerisindeki fonksiyon kullanımı yhackup 10 10.167 09-04-2023, Saat: 02:17
Son Yorum: gogo72
  Fonksiyon Çağırım Düzeni/Biçimi/Şekli Ya da Her Neyse ismailkocacan 4 4.887 05-08-2020, Saat: 20:29
Son Yorum: mrmarman
  Tasarım Desenleri : Factory Method uparlayan 16 15.554 05-02-2019, Saat: 12:34
Son Yorum: boreas
Thumbs Up Inline Fonksiyon,Procedure narkotik 7 7.292 19-05-2018, Saat: 10:42
Son Yorum: sabanakman
  Pascal Dersleri #5 - Değişken Tipleri AliZairov 0 2.347 02-05-2017, Saat: 20:45
Son Yorum: AliZairov



Konuyu Okuyanlar: 1 Ziyaretçi