Autor Beitrag
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 16:19 
Ich habe eine eigene Klasse geschrieben die folgender maßen aussieht:

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
unit EngineObjectU;

interface
uses DGLOpenGL,EngineTextureManagerU;
Type
 TEngineObject = Class(TObject)
 private
   var
    Pos             : Array[1..3] of real;
    ObjectKind      : String;
    ObjectIndex     : Integer;
    ObjectSize      : real;
  public
   Procedure Init(Index : Integer; Size : Real; EOKind : string);
   Procedure DrawObject;
   Procedure Moveto(X,Y,Z :Real);
   function GetPos(axis : integer) : real;
   function GetIndex : Integer;
   function GetKind : string;
   var
    Active : Boolean;
 End;
implementation

Procedure TEngineObject.Init(Index: Integer; Size:Real; EOKind: String);
var i : integer;
begin
  ObjectKind  := EOKind;
  ObjectIndex := Index;
  ObjectSize  := Size;
  Active      := False;
  for i := 1 to 3 do Pos[i] := -1;
end;

procedure TEngineObject.DrawObject;
begin
 if Active then
  begin
   If ObjectKind = 'EOBOX'   then EOTextureManager.BindTexture('box.JPG');
   If ObjectKind = 'EOPWRUP' then EOTextureManager.BindTexture('mushroom.JPG');
   If ObjectKind = 'EOFOE'   then EOTextureManager.BindTexture('foe.JPG');
   glinitnames;
   glpushname(ObjectIndex);
   glbegin(GL_Quads);
    glTexCoord2f(0,0); glvertex3f((Pos[1]-1)*ObjectSize,(Pos[2]-1)*ObjectSize,Pos[3]);
    glTexCoord2f(0,1); glvertex3f((Pos[1]+1)*ObjectSize,(Pos[2]-1)*ObjectSize,Pos[3]);
    glTexCoord2f(1,1); glvertex3f((Pos[1]+1)*ObjectSize,(Pos[2]+1)*ObjectSize,Pos[3]);
    glTexCoord2f(1,0); glvertex3f((Pos[1]-1)*ObjectSize,(Pos[2]+1)*ObjectSize,Pos[3]);
   glend;
  end;
end;

procedure TEngineObject.Moveto(X: Real; Y: Real; Z: Real);
begin
 Pos[1] := X;
 Pos[2] := Y;
 Pos[3] := Z;
end;

function TEngineObject.GetPos(axis: Integer) : real;
begin
 result := Pos[Axis];
end;

function TEngineObject.GetIndex : integer;
begin
 result := ObjectIndex;
end;

function TEngineObject.GetKind : string;
begin
 result := ObjectKind;
end;

end.



Wenn ich jetzt ein Engine object erstellen möchte mache ich folgendes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
var
 EOCount : Integer;
...
 EOCount := 0;
...
 while i <  Helplist.Count do
 begin
  inc(EOCount,1);

  showmessage('Haltepunkt1');
 
   EObject[EOCount].Create;
  
  showmessage('Haltepunkt2');

  EObject[EOCount].Init(EOCount,1,Helplist.Strings[i-1]); 
  EObject[EOCount].Moveto(strtofloat(Helplist.Strings[i]),
                          strtofloat(Helplist.Strings[i+1]),
                          strtofloat(Helplist.Strings[i+2]));  
  inc(i,4);
 end;


Haltepunkt 1 kommt noch aber Nr2 nicht da Fehlermeldung!


Zuletzt bearbeitet von Jerk am Sa 17.05.08 18:07, insgesamt 4-mal bearbeitet
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 16:25 
Lass mal die var innerhalb der Klassendefinition weg.
Init würde ich durch einen überladenen Konstruktor machen

_________________
Markus Kinzler.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 16:32 
*edit* hab mich vertan;


Zuletzt bearbeitet von Jerk am Sa 17.05.08 16:48, insgesamt 1-mal bearbeitet
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 16:37 
Ich meinte die Schlüsselwörter var nicht die Eigenschaften an sich

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Type
 TEngineObject = Class(TObject)
 private
    Pos             : Array[1..3] of real; 
...

_________________
Markus Kinzler.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 16:48 
Wenn ich kein Array benutze sondern ein einzelnes Objekt dann funktioniert es...


Zuletzt bearbeitet von Jerk am Sa 17.05.08 18:09, insgesamt 1-mal bearbeitet
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 17:47 
Wie sieht der Schleifenkopf aus?

_________________
Markus Kinzler.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 17:56 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
 var
 EOCount : Integer;
...
 EOCount := 0;
...
 while i <  Helplist.Count do
 begin
  inc(EOCount,1);

  showmessage('Haltepunkt1');
 
   EObject[EOCount].Create;
  
  showmessage('Haltepunkt2');
  EObject[EOCount].Init(EOCount,1,Helplist.Strings[i-1]); 
  EObject[EOCount].Moveto(strtofloat(Helplist.Strings[i]),
                          strtofloat(Helplist.Strings[i+1]),
                          strtofloat(Helplist.Strings[i+2]));  
  inc(i,4);
 end;
end;


Haltepunkt 1 kommt, dann kommt der Fehler.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Sa 17.05.08 18:04 
Preisfrage.. wo ist der Unterschied? ;)
1:
ausblenden Delphi-Quelltext
1:
  EObject[i] := TEngineObject.Create;					


2:
ausblenden Delphi-Quelltext
1:
  EObject[EOCount].Create;					

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 18:06 
Ja das war für das Beispiel hier im forum, macht jedenfalls kein Unterschied.
Hab den eröffnungspost mal editiert.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 18:12 
Warum änderst du den Code, wenn man darauf geantwortet hat und sich darauf bezieht?
Zitat:
Ja das war für das Beispiel hier im forum, macht jedenfalls kein Unterschied.

EObject[EOCount].Create; ist kein Aufruf des Konstruktors sondern ein normaler Methodenaufruf auf ein nicht existentes Objekt

_________________
Markus Kinzler.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 17.05.08 22:05 
Ich seh grad was du meinst -.-
ausblenden Delphi-Quelltext
1:
EObject[EOCOunt] := TEngineObject.Create;					

Man manchmal bin ich echt zu dumm...
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: So 18.05.08 11:10 
Zur Erklärung: ein Konstruktor ist intern nichts anderes als eine normale Methode die vom Compiler speziell behandelt wird. Wenn er über eine (Meta)Klasse aufgerufen wird (TEngineObject.Create;), dann fügt der Compiler intern einen Aufruf von ClassCreate ein, der eine Instanz dieser Klasse erzeugt und initialisiert und für diese Instanz dann den Konstruktor aufruft.
Wird der Konstruktor hingegen direkt über eine Objekt-Variable aufgerufen (EObject[EOCount].Create;) so wird der Konstruktor als ganz normale Methode für dieses Objekt aufgerufen. Da in deinem Fall aber noch kein Objekt existiert kommt es eben zu einer Exception.

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: So 18.05.08 13:02 
Das ist ungefähr so als ob du sich selbst zeugen wolltest ;)

gruß