Autor Beitrag
karatekid234
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mo 11.12.06 21:24 
Ich habe eine Klasse, die sich vom Panel ableitet. Darin sind Shapes als Array untergebracht, also "boxen:array [0..20] of TShape".
Wieso kann ich nicht einfach in Form von

namederklasse.boxen[x].visible:=false

benutzen, um die Shapes im Constructor unsichtbar zu machen. Delphi meldet mir einen Exception Fehler.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 11.12.06 22:38 
Moin und :welcome: im Forum!

user profile iconkaratekid234 hat folgendes geschrieben:
Delphi meldet mir einen Exception Fehler.

Delphi meldet Fehler immer mit einer Exception, es wäre also schon interessant, WELCHE und WAS GENAU da ausgegeben wird. ;)

Klassisch ist da aber meistens, dass das entsprechende Objekt einfach (noch) nicht initialisiert wurde (also mit Boxen[i] := TShape.Create(Parent); angelegt wurde), so dass du auf eine ungültige Adresse zugreifst.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
karatekid234 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 12.12.06 10:47 
---------------------------
Benachrichtigung über Debugger-Exception
---------------------------
Im Projekt Project1.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 004572E2 in Modul 'Project1.exe'. Schreiben von Adresse 0000022C'. Prozess wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen.
---------------------------
OK Hilfe
---------------------------

EDIT1: panel1.steine[lauf]:=TShape.Create(self);

wieso reicht ihm da nicht? bzw. wenn ich "panel1" nicht schreibe, dann macht er alle steine sichtbar (auch auf panel2 und 3), wenn ich aber sagen will, dass er in einem betimmten panel die steine unsichtbar machen soll, dann kommt die exception.


Zuletzt bearbeitet von karatekid234 am Di 12.12.06 10:52, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.12.06 10:49 
Moin!

user profile iconkaratekid234 hat folgendes geschrieben:
---------------------------
Benachrichtigung über Debugger-Exception
---------------------------
Im Projekt Project1.exe ist eine Exception der Klasse EAccessViolation aufgetreten. Meldung: 'Zugriffsverletzung bei Adresse 004572E2 in Modul 'Project1.exe'. Schreiben von Adresse 0000022C'. Prozess wurde angehalten. Mit Einzelne Anweisung oder Start fortsetzen.
---------------------------
OK Hilfe
---------------------------

user profile iconNarses hat folgendes geschrieben:
Klassisch ist da aber meistens, dass das entsprechende Objekt einfach (noch) nicht initialisiert wurde (also mit Boxen[i] := TShape.Create(Parent); angelegt wurde), so dass du auf eine ungültige Adresse zugreifst.

:mrgreen:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
monster
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 51

Win XP
Delphi 2005 PE
BeitragVerfasst: Di 12.12.06 10:57 
ich schätze alle die genial genug sind, von der exception auf die ursache des problems zu schließen, wurden längst von microsoft angeworben, daher bleibt uns wohl nichts anderes übrig, als das problem analytisch anzugehen.

1. Hast Du der Variablen eine neue Objektinstanz a la "shape := TShape.Create(sender);" zugewiesen?
2. Haben die Shapeinstanzen als Parent eine Form oder sowas, damit sie auch dargestellt werden können?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.12.06 11:17 
Moin!

user profile iconmonster hat folgendes geschrieben:
daher bleibt uns wohl nichts anderes übrig, als das problem analytisch anzugehen.

Wie du das machen willst, wenn user profile iconkaratekid234 kaum Code zeigt, ist allerdings die spannendere Frage... ;) Deshalb bleibt ja praktisch nur das beliebte Ratespiel (habe nie behauptet, DAS ist es). :zwinker:

user profile iconkaratekid234 hat folgendes geschrieben:
panel1.steine[lauf]:=TShape.Create(self);

Wer ist denn hier "Self", jetzt zeig doch endlich mal etwas mehr Code... :roll: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
karatekid234 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 12.12.06 11:29 
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:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
unit Unit1;

interface

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

type

 Tturm = class (TPanel)
  private
    { Private-Deklarationen }
     Fsize: integer;
    steine: array[0..10] of TShape;
    stab: TShape;
    procedure setsize(size: integer);
    function getsize: integer;
    constructor create(TurmTop, TurmLeft, TurmWidth, TurmHeight:integer; hinten: TComponent); virtual;
  public
    { Public-Deklarationen }
    property size:integer read getsize write setsize ;
    end;


  TForm1 = class(TForm)
    Label1: TLabel;
    SpinEdit1: TSpinEdit;
    Label2: TLabel;
    TrackBar1: TTrackBar;
    Button1: TButton;
    Button2: TButton;
    SpinEdit2: TSpinEdit;
    Label3: TLabel;
    procedure FormCreate(Sender: TObject);
  private
   versuch:longint;
    procedure umsetzen(anzahl, von, nach, hilf : integer);
    procedure setze_eine(von,nach : integer);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  spinx:Integer;
  Tturm1, Tturm2, Tturm3 : Tturm;
implementation


procedure TForm1.umsetzen(anzahl, von, nach, hilf : integer);
   begin
   if anzahl=1 then setze_eine(von,nach)
   else begin
       umsetzen(anzahl-1,von,hilf,nach);
       umsetzen(1,von,nach,hilf);
       umsetzen(anzahl-1,hilf,nach,von);
       end;
   end;

   procedure TForm1.setze_eine(von,nach : integer);
    var jetzt:integer;
   begin
   inc(versuch);
        Jetzt := GetTickCount + SpinEdit2.value;
        REPEAT
            Application.ProcessMessages;
        UNTIL GetTickCount > Jetzt;
   form1.Refresh;
   end;

   {$R *.dfm}
procedure Tturm.setsize(size: integer);
   var lauf: integer;
        raster:word;
   begin
   Fsize:=size;
   width:=size;
   height:=size;
   raster:=size div 20;
   for lauf:=0 to spinx-1 do begin
      with steine[lauf] do begin
        top:=17*raster-lauf*raster;
        left:=(raster+lauf*raster);
        width:=17*raster-lauf*raster*2;
        height:=3*raster;
        end;
      end;
   end;

   function Tturm.getsize: integer;
   begin
   result:=Fsize;
   end;

   constructor Tturm.create(TurmTop, TurmLeft, TurmWidth, TurmHeight:integer; hinten: TComponent);
   var lauf: integer;
        raster:word;
   begin
   inherited create(hinten);
   Parent:=TWincontrol(hinten);
   Top:=TurmTop;
   left:=TurmLeft;
   width:=TurmWidth;
   height:=TurmHeight;
   color:=clwhite;
   FSize:=TurmWidth;
   raster:=Fsize div 25;
   for lauf:=0 to spinx-1 do begin
      steine[lauf]:=TShape.Create(self);
      with steine[lauf] do begin
        parent:=self;
        Shape:=strectangle;
        brush.Color:=clblue;
        pen.Color:=clcream;
        top:=25*raster-lauf*raster;
        left:=(raster+lauf*raster)+20;
        width:=17*raster-lauf*raster*2;
        height:=raster;
        end;
      end;
      for lauf:=0 to spinx-1 do begin
      steine[lauf]:=Tshape.Create(self);
      with tturm2.steine[lauf] do begin
      visible:=false;
      end;
      end;
      Stab:=TShape.create(self);
      Stab.Parent:=self;
         with stab do begin
           top:=11*raster-2;
           left:=(25*raster div 2) ;
           width:=raster;
           height:=15*raster;
           brush.Color:=Clgray;
           pen.Color:=clgray;
           end
   end;

procedure TForm1.FormCreate(Sender: TObject);
var
  raster:integer;
begin
raster:=trackbar1.Position div 25;
spinx:=spinedit1.value;
if (tturm1 <> nil) then tturm1.Free;
if (tturm2 <> nil) then tturm2.Free;
if (tturm3 <> nil) then tturm3.Free;
  tturm1:=Tturm.Create(75, 10, raster*6, raster*7, Form1);
  tturm2:=Tturm.Create(75, tturm1.width+20, raster*6,raster*7, Form1);
  tturm3:=Tturm.Create(75, tturm1.Width*2+30, raster*6,raster*7, Form1);
end;


end.
karatekid234 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 12.12.06 13:29 
So, da ist der gesamt Quellcode. Ich hoffe, dass ihr mir jetzt helfen könnt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.12.06 15:46 
Moin!

user profile iconkaratekid234 hat folgendes geschrieben:
So, da ist der gesamt Quellcode. Ich hoffe, dass ihr mir jetzt helfen könnt

Zur Info: Schiebepostings sind hier erst nach 24 Stunden erlaubt! :mahn:

Schätze, dein Problem liegt hier:
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:
constructor Tturm.create(TurmTop, TurmLeft, TurmWidth, TurmHeight:integer; hinten: TComponent);  
   var lauf: integer;  
        raster:word;  
   begin  
   inherited create(hinten);  
   Parent:=TWincontrol(hinten);  
   Top:=TurmTop;  
   left:=TurmLeft;  
   width:=TurmWidth;  
   height:=TurmHeight;  
   color:=clwhite;  
   FSize:=TurmWidth;  
   raster:=Fsize div 25;  
   for lauf:=0 to spinx-1 do begin  
      steine[lauf]:=TShape.Create(self); // 1. mal erzeugen, ok
      with steine[lauf] do begin  
        parent:=self;  
        Shape:=strectangle;  
        brush.Color:=clblue;  
        pen.Color:=clcream;  
        top:=25*raster-lauf*raster;  
        left:=(raster+lauf*raster)+20;  
        width:=17*raster-lauf*raster*2;  
        height:=raster;  
        end;  
      end;  
      for lauf:=0 to spinx-1 do begin  
      steine[lauf]:=Tshape.Create(self); // nochmal erzeugen!?! :shock:
      with tturm2.steine[lauf] do begin // turm2 dürfe beim create von turm1 doch noch gar nicht existieren... ?!
      visible:=false;  
      end;  
      end;  
      Stab:=TShape.create(self);  
      Stab.Parent:=self;  
         with stab do begin  
           top:=11*raster-2;  
           left:=(25*raster div 2) ;  
           width:=raster;  
           height:=15*raster;  
           brush.Color:=Clgray;  
           pen.Color:=clgray;  
           end  
   end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.