Autor Beitrag
perry5
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mo 18.12.06 18:12 
Hi, ich hab 2 Procedure in einer Unit.
So alleine sind die ja doof, aber in ne Klasse packen, die ich erst erstellen udn freigeben muss ist noch doofer.
Wenn meine Funktion jetzt GetCommand() heißt, möchte ich z.b. schreiben Parser.GetCommand()
Wie mach ich das am einfachsten?
Bei C++ gibts ja Namespaces mit dnene man das amchen kann, oder man amcht die Klasse static, dann brauch man auch kein Objekt zu erstellen, wie geht sowas mit Delphi?
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Mo 18.12.06 18:17 
mit class function bla

myclass.bla;
perry5 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mo 05.02.07 23:32 
Dann muss ich aber ein myclass Objekt anlegen, oder? Ich wills ja eben ganz ohne Objekt, sondern nur mit ner Klasse machen.

Den irgendwie ghet das SO nicht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
type CParser = class

function GetCommand(p_Text : string) : string;
function GetParameterString(p_Text: string; p_Count : integer) : string;
function GetParameterReal(p_Text: string; p_Count : integer) : real;
function GetParameterInt(p_Text: string; p_Count : integer) : integer;

end;



...




function CParser.GetParameterReal(p_Text : string; p_Count : integer) : real;
begin
 result:=strtofloat(CParser.GetParameterString(p_Text, p_Count));
end;


function CParser.GetParameterInt(p_Text : string; p_Count : integer) : integer;
begin
 result:=strtoint(CParser.GetParameterString(p_Text, p_Count));
end;


[Fehler] Parser.pas(58): Diese Form des Methodenaufrufs ist nur für Klassenmethoden erlaubt
perry5 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mi 07.02.07 22:49 
Das muss doch irgendwie gehen??
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 07.02.07 23:24 
Hallo!

Es muss ja auch "class function" heissen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type
  TMyClass = class
  public
    class function foo : Integer;
  end;

...



Und dann musst auch auch keine Instanz anlegen. :-)

Gruesse
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".