Autor Beitrag
nepleurepas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164

Win XP

BeitragVerfasst: Mi 09.05.07 15:30 
Hallo,
in meinem Programm wird die procedure animation durch eine onclick procedure aufgerufen. Animation zeichnet dann sternkarten auf ein image, die sich im lauf der zeit bewegen. Nun wollte ich, dass das image vor beginn der procedure animation ersteinmal "gecleared" wird. Habe deswegen die procedure cleardraw davor gesetzt. Seitdem ich das gemacht habe, flimmert das bild während der animation sehr stark, geradezu so, als ob die procedure cleardraw immer wieder aufgerufen werden würde., was ja eig. nicht sein darf. Hoff mal mir kann jemand helfen.

hier erst mal etwas code...
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:
procedure cleardraw ;
begin
form2.image1.Canvas.Brush.Color:= clwhite;
form2.image1.canvas.FillRect(rect(0,0,form2.Image1.width,form2.Image1.height));


procedure animation ;
var t, tmax, jahrist, jahrbis, delay, schrittweite: integer;
var farbe: Tcolor;
begin

schrittweite:= strtoint(form2.Edit8.text);
delay:= strtoint(form2.edit7.Text);
jahrist:= strtoint(form2.edit2.Text);
jahrbis:= strtoint(form2.Edit3.Text);
farbe:= form1.colorbox1.selected;
form2.Image1.Height:= strtoint(form2.edit5.Text);
form2.image1.Width:= strtoint(form2.edit5.Text);
form2.Image1.BringToFront;

while (jahrist<=jahrbis) do
  begin
  kreis(farbe);
  form2.edit2.Text:= inttostr(jahrist);
  form2.Edit4.Text:= inttostr(jahrist);
  zeichnebank((jahrist+1501),farbe);
  application.ProcessMessages;
  if form2.Button3.tag=1 then
    begin
    form2.Button3.Tag:= 0;
    exit;
    end;
  sleep(delay);
  if ((jahrist+schrittweite)<=jahrbis) then
  zeichnebank((jahrist+1501),clwhite);
  jahrist:= jahrist+schrittweite;
  end;
end;


procedure TForm2.Button2Click(Sender: TObject);
begin
cleardraw;
animation2au.animation;
end;



danke schonmal für antworten
Gruß0 Stefan
LDMatrix17
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 73

xXpProOxsP2x
Flash5~Flash7 MX 2004 Prof.~Flash 8 Prof.~Delphi 7 prof.&HTML
BeitragVerfasst: Mi 09.05.07 15:36 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure cleardraw ;
begin
form2.image1.Canvas.Brush.Color:= clwhite;
form2.image1.canvas.FillRect(rect(0,0,form2.Image1.width,form2.Image1.height));

/// <--------- fehlt hier kein END; ???
//  wenn nicht rufst du beim clearn auch animation auf!!


Moderiert von user profile iconChristian S.: Delphi-Tags repariert

_________________
~sOm3!~gUrLs!~sOm3!~dAyS!~L!f3~iS!~nOT!~bOriNg!!~
nepleurepas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164

Win XP

BeitragVerfasst: Mi 09.05.07 16:14 
user profile iconLDMatrix17 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure cleardraw ;
begin
form2.image1.Canvas.Brush.Color:= clwhite;
form2.image1.canvas.FillRect(rect(0,0,form2.Image1.width,form2.Image1.height));

/// <--------- fehlt hier kein END; ???
//  wenn nicht rufst du beim clearn auch animation auf!!



Hab nur vergessen das end zu kopieren, is aber im programm schon da. Also daran liegts ganz siche rnich.
LDMatrix17
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 73

xXpProOxsP2x
Flash5~Flash7 MX 2004 Prof.~Flash 8 Prof.~Delphi 7 prof.&HTML
BeitragVerfasst: Mi 09.05.07 16:34 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm2.Button2Click(Sender: TObject);
begin

 cleardraw;
 ShowMessage('test');
 Animation(nil);
 //animation2au.animation;
end;


Versuch mal soO..
bekommst du mehrmals Meldungen angezeigt??

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt

_________________
~sOm3!~gUrLs!~sOm3!~dAyS!~L!f3~iS!~nOT!~bOriNg!!~
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 09.05.07 16:40 
Moin!

Von dem Code-Schnipselchen werden wir wohl nicht schlau... :?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm2.Button2Click(Sender: TObject);
begin
  cleardraw;
  animation2au.animation;
end;

Sehr viel interessanter wäre, was hier passiert?! :nixweiss:

cu
Narses

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

Win XP

BeitragVerfasst: Mi 09.05.07 18:29 
hab den test mit der showmessage gemacht. die procedure wird definitiv nur einmal durchlauefen. Hab aber eine absolut unerklärliche entdeckung gemacht. Das Flackern hängt von gänzlich unabhängigen Faktoren ab.

Habe folgende Procedure eingebaut:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm2.FormCreate(Sender: TObject);
begin
image1.height:= 5000 ;
image1.Width:= 5000;
image1.canvas.Ellipse(0,0,5000,5000);
end;


Seitdem gibt es kein Flackern mehr!!!!
Sobald ich die TFomr2.FormCreate procedure wieder rausnehm, tritt bei animation wieder Flackern auf!!

Kann mir das jemand erklären?
Wers nicht glaubt, ich schicke auch gerne mal das Programm zu.


Zuletzt bearbeitet von nepleurepas am Mi 09.05.07 18:31, insgesamt 1-mal bearbeitet
nepleurepas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164

Win XP

BeitragVerfasst: Mi 09.05.07 18:31 
user profile iconNarses hat folgendes geschrieben:
Moin!

Von dem Code-Schnipselchen werden wir wohl nicht schlau... :?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm2.Button2Click(Sender: TObject);
begin
  cleardraw;
  animation2au.animation;
end;

Sehr viel interessanter wäre, was hier passiert?! :nixweiss:

cu
Narses


Was bei animation2au passiert ist beim themenanfang erklärt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 09.05.07 21:42 
Moin!

user profile iconnepleurepas hat folgendes geschrieben:
Was bei animation2au passiert ist beim themenanfang erklärt.

Willst du damit sagen, dass das der Aufruf der Prozedur animation ist (also die 2. im Quelltext oben)? :|

user profile iconnepleurepas hat folgendes geschrieben:
Das Flackern hängt von gänzlich unabhängigen Faktoren ab.

Nene, das hängt davon ab:
user profile iconnepleurepas hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure animation ;
var t, tmax, jahrist, jahrbis, delay, schrittweite: integer;
var farbe: Tcolor;
begin

schrittweite:= strtoint(form2.Edit8.text);
delay:= strtoint(form2.edit7.Text);
jahrist:= strtoint(form2.edit2.Text);
jahrbis:= strtoint(form2.Edit3.Text);
farbe:= form1.colorbox1.selected;
form2.Image1.Height:= strtoint(form2.edit5.Text);
form2.image1.Width:= strtoint(form2.edit5.Text);

form2.Image1.BringToFront;
//...

Wenn du die Bildgröße setzt, dann wird das interne Bitmap neu angelegt, und dessen erneute Ausgabe flackert dann. :idea: Einmal am Anfang der Animation die Größe festlegen und dann immer nur neu zeichnen. :mahn: ;)

cu
Narses

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

Win XP

BeitragVerfasst: Mi 09.05.07 22:28 
Zitat:

Willst du damit sagen, dass das der Aufruf der Prozedur animation ist (also die 2. im Quelltext oben)? :|


animation2au.animation ist der aufruf der procedure animation in der unit animation2au.

Zitat:

Nene, das hängt davon ab:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
form2.Image1.Height:= strtoint(form2.edit5.Text);
form2.image1.Width:= strtoint(form2.edit5.Text);
form2.Image1.BringToFront;
//...

Wenn du die Bildgröße setzt, dann wird das interne Bitmap neu angelegt, und dessen erneute Ausgabe flackert dann. :idea: Einmal am Anfang der Animation die Größe festlegen und dann immer nur neu zeichnen. :mahn: ;)



Die Bildgröße wird doch nur einmal zu beginn von animation gesetzt.(6.+7. Befehl in animation). Wichtig: Animation wird nicht wiederholt!!! Die Wiederholungen finden in animation statt, in folgender schleife:
ausblenden Delphi-Quelltext
1:
2:
while jahrist<=jahrbis
...


Verstehe nicht wie du darauf kommst, die bildgröße würde ständig neu gesetzt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 09.05.07 22:33 
Moin!

user profile iconnepleurepas hat folgendes geschrieben:
Zitat:

Willst du damit sagen, dass das der Aufruf der Prozedur animation ist (also die 2. im Quelltext oben)? :|

animation2au.animation ist der aufruf der procedure animation in der unit animation2au.

Ja, klar; aber ist das die genannte Proc oder nicht? :nixweiss:

user profile iconnepleurepas hat folgendes geschrieben:
Die Bildgröße wird doch nur einmal zu beginn von animation gesetzt.(6.+7. Befehl in animation). Wichtig: Animation wird nicht wiederholt!!! Die Wiederholungen finden in animation statt,

Öhhh :? klar... :oops: wer lesen kann... :|

Was passiert denn in zeichebank()?

cu
Narses

//EDIT: Ach ja, haste in Form2 im FormCreate die Eigenschaft .DoubleBuffered := TRUE gesetzt?

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

Win XP

BeitragVerfasst: Do 10.05.07 00:46 
wird wohl zeit für etwas mehr code..
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:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
procedure zeichnebank(t: integer; farbe: Tcolor)  ;
var  zeile: integer;
var name: string;
var x, y: real;
begin

  zeile:= 1;
  while (zeile<=zeilenanzahl) do
    begin    name:= bank[t,zeile].name;
    x:= bank[t,zeile].x;
    y:= bank[t,zeile].y;
    form1.StringGrid1.Cells[1,zeile]:= name;
    form1.stringgrid1.Cells[4,zeile]:= floattostr(x);
    form1.stringgrid1.cells[5,zeile]:= floattostr(y);
    form1.stringgrid1.cells[6,zeile]:= inttostr(t-1501);
    zeichnestern(x,y,name,farbe);
    zeile:= zeile+1;
    end;
end;


procedure animation ;
var t, tmax, jahrist, jahrbis, delay, schrittweite: integer;
var farbe: Tcolor;
begin
if (form2.CheckBox1.checked=false) then spur:= false
                                   else spur:= true;

schrittweite:= strtoint(form2.Edit8.text);
delay:= strtoint(form2.edit7.Text);
jahrist:= strtoint(form2.edit2.Text);
jahrbis:= strtoint(form2.Edit3.Text);
farbe:= form1.colorbox1.selected;
form2.Image1.Height:= strtoint(form2.edit5.Text);
form2.image1.Width:= strtoint(form2.edit5.Text);
form2.Image1.BringToFront;

while (jahrist<=jahrbis) do
  begin
  kreis(farbe);
  ekliptik(nutation(jahrist+1501));
  wendekreise(nutation(jahrist+1501));
  form2.edit2.Text:= inttostr(jahrist);
  form2.Edit4.Text:= inttostr(jahrist);
  zeichnebank((jahrist+1501),farbe);
  application.ProcessMessages;
  if form2.Button3.tag=1 then
    begin
    form2.Button3.Tag:= 0;
    exit;
    end;
  sleep(delay);
  if ((jahrist+schrittweite)<=jahrbis)  then
  {zeichnebank((jahrist+1501),clwhite); }
  if (spur=false) then cleardraw;
  jahrist:= jahrist+schrittweite;
  end;
end;

function ArithRound(x: Extended): Int64;
begin
  if frac(x) < 0.5 then result := floor(x)
  else result := ceil(x);
end;



function nutation(t: integer): real;
begin
result:= (t*0.0074285714+26.4)/60+23
end;


function umrechnen(z: real; zentrum, zoom: integer): integer;
begin
  result:= zentrum-(arithround(z*zoom));
end;




procedure zeichnestern(x,y: real; name: string; farbe: Tcolor);
var px, py, dicke, zoom, zentrum, size: integer;
begin
size:= strtoint(form1.edit8.Text);

  zoom:= strtoint(form2.Edit6.Text);
  zentrum:= print2u.arithround(form2.Image1.Width/2);


  dicke:= strtoint(form1.edit3.text);

  form2.Image1.canvas.Pen.Width:= 1;
  form2.Image1.canvas.brush.Color:= farbe;
  form2.Image1.canvas.Pen.Color:= farbe;
  px:= umrechnen((-x),zentrum,zoom);
  py:= umrechnen(y,zentrum,zoom);

  {if (spur=false) or ((spur=true) and (farbe=clblack)) then }form2.Image1.Canvas.roundrect(px-dicke,py-dicke,px+dicke,py+dicke,100,100);
  form2.Image1.Canvas.Brush.Color:= clwhite;
  form2.Image1.canvas.font.Color:= farbe;
  form2.image1.canvas.Font.Size:= size;
  if (spur=false) then form2.Image1.Canvas.TextOut(px,py+5,name);



end;

procedure wendekreise(phi: real);
var radius, y: extended;
var zoom, zentrum, py, pradius: integer;
begin
zoom:= strtoint(form2.Edit6.Text);
zentrum:= print2u.arithround(form2.Image1.Width/2);

radius:= (-cos(degtorad(phi)))/(sin(degtorad(phi))+1);
pradius:= arithround(zoom*radius);

form2.image1.canvas.pen.Width:= 1;
form2.Image1.Canvas.Pen.Color:= clblack;
form2.image1.canvas.brush.style:= bsclear;
form2.Image1.canvas.Ellipse((zentrum-pradius),(zentrum-pradius),(zentrum+pradius),(zentrum+pradius));

radius:= (cos(degtorad(phi)))/(1-sin(degtorad(phi)));
pradius:= arithround(zoom*radius);

form2.Image1.canvas.Ellipse((zentrum-pradius),(zentrum-pradius),(zentrum+pradius),(zentrum+pradius));

end;





procedure ekliptik(phi: real) ;
var radius, y: extended;
var zoom, zentrum, py, pradius: integer;
begin
zoom:= strtoint(form2.Edit6.Text);
zentrum:= print2u.arithround(form2.Image1.Width/2);

y:= tan(degtorad(phi));
radius:= 1/(cos(degtorad(phi)));

py:= umrechnen(-y,zentrum,zoom);
pradius:= arithround(zoom*radius);


form2.image1.canvas.Pen.Color:= clblue;
form2.image1.canvas.Pen.Width:= 2;
form2.image1.canvas.brush.style:= bsclear;
form2.Image1.canvas.ellipse((zentrum-pradius),(py-pradius),(zentrum+pradius),(py+pradius));

end;

procedure kreis(farbe: Tcolor);
var zentrum, zoom: integer;
begin
  zoom:= strtoint(form2.Edit6.Text);
  zentrum:= print2u.arithround(form2.Image1.Width/2);
  form2.image1.canvas.brush.Style:= bsclear;
  form2.image1.canvas.Pen.Width:= 2;
  form2.Image1.Canvas.Pen.Color:= clblack;
  form2.Image1.canvas.Ellipse(zentrum-zoom,zentrum-zoom,zentrum+zoom,zentrum+zoom);

end;


hoffe es hilft weiter, kann aber jetz schon sagen, dass in den anderen procedure die bildgröße nirgends mehr verändert wird. Es flimmt ja auch nicht mehr, seitdem ich diese ominöse oncreate procedure drin habe. Jetzt kann ich sogar bei jeden schleifendurchlauf ein cleardraw einbauen, ohen dass es flimmert. Das Flimmern hat irgendwelche andere Ursachen, die nicht so offensichtlich sind, leider. Wer mir diese Ursachen nennen kann genießt mein vollen respekt.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 10.05.07 08:52 
Moin!

Nochwas grundsätzliches: ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure animation ;
//...
while (jahrist<=jahrbis) do
  begin
  //...
  application.ProcessMessages;
  if form2.Button3.tag=1 then begin
    form2.Button3.Tag:= 0;
    exit;
  end;
  sleep(delay);
  if ((jahrist+schrittweite)<=jahrbis)  then
  {zeichnebank((jahrist+1501),clwhite); }
  if (spur=false) then cleardraw;
  jahrist:= jahrist+schrittweite;
  end;
end;

Das entspricht nicht dem Konzept einer ereignisorientierten Anwendung, was immer "interessante" Nebeneffekte haben könnte. Wie man das anders machen kann, ist in diesem FAQ-Beitrag beschrieben. :idea: ;)

user profile iconnepleurepas hat folgendes geschrieben:
Es flimmt ja auch nicht mehr, seitdem ich diese ominöse oncreate procedure drin habe. Jetzt kann ich sogar bei jeden schleifendurchlauf ein cleardraw einbauen, ohen dass es flimmert.

Weil du mehr Ressourcen für das Image anforderst, verschiebt sich das Timing, soweit ist das schon klar. Unklar ist nur, wo der Splitpoint für die Sichtbarkeit ist. :?

user profile iconnepleurepas hat folgendes geschrieben:
Das Flimmern hat irgendwelche andere Ursachen, die nicht so offensichtlich sind

Das liegt am Neuzeichnen des Images, soviel ist auch klar. :| Deshalb: Form2.DoubleBuffered := TRUE gesetzt? Wenn das noch nicht hilft, könnte es auch noch am Suche in: Delphi-Forum, Delphi-Library WM_ERASEBACKGROUND für das Formular liegen, das ggfs. fangen und ignorieren. :idea:

cu
Narses

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

Win XP

BeitragVerfasst: Do 10.05.07 11:54 
danke für die tipps. werd mal schaun was ich damit anfangen kann.