Autor Beitrag
coolreaper
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Fr 22.04.05 11:06 
Ich arbeite gerade kräftig an einem Info-Projekt, der einen springenden Ball simuliert. So weit, so gut, so einfach....

Nun werden allerdings auch Klassen gefordert und ich plane, eine Klasse Ball zu kreieren, damit eine große Anzahl von Bällen auf einem Panel herumspringen können.... Doch weder ich, noch meine Frau Lehrerin, ncoh irgendwelche Recherchen verraten mir, wo ich den Fehler in meinem Code veranstaltet habe...

Hier der relevante Ausschnitt:
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type

TBall = class(TShape)
  Constructor Create(Owner: TComponent);
  Destructor Destroy; override;
  public
    procedure Wurf(a :real; v:real; left:Integer;top:Integer);
  private
    speed, winkel: real;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

constructor TBall.Create(Owner: TComponent);
begin
  inherited Create(Owner);
  Brush.Color:=clMaroon;
  Shape:=stCircle;
  height:=17;width:=17;
  top:=100;left:=100;
  visible:=true;
end;

destructor TBall.Destroy;
begin
  inherited Destroy;
end;

procedure TBall.Wurf(a :real; v:real; left:Integer;top:Integer);
begin

end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  TBall.Create(self);
end;

end.


Ich danke allen, die sich diesem Problem widmen!

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Fr 22.04.05 11:13 
Hi und :welcome:!
Ich nehm an, dein Problem ist, dass du den Ball nicht siehst (solltest du nächstes Mal sagen ;))
Um diesen Fehler zu beheben setzst du das parent des Balls einfach auf Form1! Sonst ist halt eben nicht klar, wo der Ball gezeichnet werden soll.
ausblenden Delphi-Quelltext
1:
2:
with TBall.Create(self) do
 parent := self;

Sowas in der Art. :)
Gruss
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.04.05 11:15 
Sorry, aber du schreibst nichtmal, um was für einen Fehler es sich handelt.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Fr 22.04.05 11:25 
Übrigens solltest du deinen Konstruktor korrekterweise so deklarieren:
 constructor Create(Owner: TComponent); override;

(Weil diese Methode in TComponent als virtual deklariert ist)
coolreaper Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Fr 22.04.05 16:08 
Ich wusste doch, das was fehlt :roll:
Aber dennoch danke!
coolreaper Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 25.04.05 13:55 
Vielen Dank für eure schnelle Hilfe, (der Code sieht nun folgendermaßen aus:
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:
unit Unit1;
 
interface  

uses  
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
 
TBall = class(TShape)  
  Constructor Create(Owner: TComponent); override;
  Destructor Destroy; override;  
  public  
    procedure Wurf(a :real; v:real; left:Integer;top:Integer);  
  private
    speed, winkel: real;  
  end;
 
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
var
  Form1: TForm1;
 
implementation

{$R *.dfm}

constructor TBall.Create(Owner: TComponent);  
begin
  inherited Create(Owner);
  Brush.Color:=clMaroon;  
  Shape:=stCircle;  
  height:=17;width:=17;
  top:=100;left:=100;  
  visible:=true;
end;

destructor TBall.Destroy;  
begin
  inherited Destroy;  
end;
 
procedure TBall.Wurf(a :real; v:real; left:Integer;top:Integer);
begin
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 with TBall.Create(self) do
 parent := self;
end;

end.


)

Aber der Ball erscheint nach wie vor nicht! :(

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Mo 25.04.05 18:02 
Könntest Du bitte auch den Rest posten?
Es ist zwar gut zu wissen, was einen erwartet, aber ohne Inhalt fehlt irgendwas
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 25.04.05 18:21 
ich verstehs auch net, ich hab das jetzt so gemacht:
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:
unit Unit1;

interface

uses    
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

type
  TBall = class(TShape)
    Constructor Create(Owner: TComponent); override;
    Destructor Destroy; override;
  public
    procedure show;
  private

  end;

var
  Form1: TForm1;
  Ball: TBall;
   
implementation  

 
{$R *.dfm}
 
constructor TBall.Create(Owner: TComponent);
begin  
  inherited;
  Create(Owner);
end;

destructor TBall.Destroy;
begin
  inherited;
  Destroy;
end;

procedure TBall.show;
begin
  Pen.Style:= psSolid;
  Pen.Color:= clBlack;
  Brush.Style:= bssolid;
  Brush.Color:= clRed;
  Shape:= stCircle;
  top:= 100; left:= 100;
  height:= 20; width:= 20;
  visible:= true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Ball:= TBall.Create(self);
  Ball.show;
end;
 
end.

Aber es ist nichts zu sehen, hab auch grad kein nachschlagewerk, ich benutze oop auch eher selten bzw garnicht :lol:
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 25.04.05 18:53 
Es funktioniert doch? ( :?: )
Das mit dem parent war doch das Problem.. Bei mir funktioniert's :)


Zuletzt bearbeitet von delfiphan am Mo 25.04.05 18:54, insgesamt 1-mal bearbeitet
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 25.04.05 18:53 
liegt aber glaube ich garnet daran, weil dann müsste das hier ja funktionieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var
  shp: Tshape;
begin
  shp:= Tshape.create(self);
  shp.left:= 50;
  shp.top:= 50;
  shp.width:= 30;
  shp.height:= 30;
  shp.shape:= stcircle;
  shp.Pen.Style:= pssolid;
  shp.Pen.Color:= clblack;
  shp.Brush.Style:= bssolid;
  shp.Brush.color:=clred;
  shp.Visible:= true;
end;

tuts aber net :?

mit dem parent entspräche das in meinem code oben, doch dem hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Ball:= TBall.Create(self);
  Ball.Parent:= self;
  Ball.show;
end;

obwohl man beim code von dir TBall.create(self).parent:= self; gereicht hätte und mit Create(self) wird self eh schon als parent übergeben oder irre ich da ? :shock: :?
Benutzername
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 210

Win XP Pro
Delphi 7 PE, D2005 Prof. SSL
BeitragVerfasst: Mo 25.04.05 20:31 
Nein, schau mal:
ausblenden Delphi-Quelltext
1:
2:
3:
TBall = class(TShape)  
  Constructor Create(Owner: TComponent);
  ...


Mit MeinBall := TBall.Create(self); weist du erstmal den Owner (Besitzer) zu.
Das MeinBall.Parent := self weist den parent zu. Und der ist soweit ich weiß auch fürs Anzeigen zuständig ;)
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 26.04.05 14:04 
dann sag mir, warum das hier nicht funzt:
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:
unit Unit1;

interface

uses    
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

type
  TBall = class(TShape)
    Constructor Create(Owner: TComponent); override;
    Destructor Destroy; override;
    procedure show;
  public

  private

  end;

var
  Form1: TForm1;
  Ball: TBall;
   
implementation  

 
{$R *.dfm}
 
constructor TBall.Create(Owner: TComponent);
begin  
  inherited Create(Owner);
end;

destructor TBall.Destroy;
begin
  inherited Destroy;
end;

procedure TBall.show;
begin
  Pen.Style:= psSolid;
  Pen.Color:= clBlack;
  Brush.Style:= bssolid;
  Brush.Color:= clRed;
  Shape:= stCircle;
  top:= 100; left:= 100;
  height:= 80; width:= 80;
  visible:= true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Ball:= TBall.Create(self);
  Ball.parent:= self;
  Ball.show;
end;
 
end.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Di 26.04.05 15:23 
:nixweiss:
Wahrscheinlich Quelltext reinkopiert und dabei vergessen, FormCreate dem entsprechenden Event zuzuweisen.

PS: Visible := True ist auch unnötig.
Einloggen, um Attachments anzusehen!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 26.04.05 15:35 
stimmt, hattest recht :D

muss ich den ball auch wieder freigeben im onclose ?
coolreaper Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 27.04.05 08:16 
Okay, Vielen Dank nochmal :D

Ich kann jetzt mit Stolz behaupten, dass es geht!
Jetzt nur noch in den Rest einarbeiten......... :?