Autor Beitrag
theo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62

Win 2000, XP, Vista; Win 7
Delphi 6, 7, 2010, MSSQL, Firebird, DevExpress
BeitragVerfasst: Mo 21.09.09 14:16 
Hallo!

Wann bzw. warum wird einer Methoden-Deklaration das Schlüsselwort "class" vorangestellt?
Was sind die Unterschiede zu einer "normalen" Deklaration.

Ich habe diese Variante vermehrt in fremden Quelltexten gefunden.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mo 21.09.09 14:21 
Dann wird dass eine sog. Klassenmethode.
Der Aufruf erfolgt dann über die Klasse, nicht über die instanz.
Deshalb gibt es allerdings auch kein self, d.h. man kann nicht auf Die Felder und normalen Methoden der Instanz zugreifen (self enthält die Klasse):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
type Texample = class
  class procedure blablabla;
end;

{..}

class procedure TExample.blablabla;
begin
  showmessage ('Blablabla');
end;


{..}

{Aufruf dann so:}
TExample
.blablabla; //statt erst eine Instanz anlegen zu müssen
theo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62

Win 2000, XP, Vista; Win 7
Delphi 6, 7, 2010, MSSQL, Firebird, DevExpress
BeitragVerfasst: Mo 21.09.09 14:24 
Danke! Habe das Prinzip verstanden. Das ist woll so ähnlich wie eine statische Klasse in C++, denk ich, oder?