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



BeitragVerfasst: Sa 04.07.09 12:57 
Hallo

Ich habe ein Problem, und ich kann den Fehler nicht finden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var t:integer=6;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
t:=t-1;
if t=5 then
 image1.picture.loadfromfile('bild01.jpg');
if t=3 then image1.picture.loadfromfile('bild02.jpg');
if t=2 then image1.picture.loadfromfile('bild03.jpg');
if t=4 then image1.picture.loadfromfile('bild04.jpg');
if t=1 then image1.picture.loadfromfile('bild05.jpg');
if t=0 then t:=6;
end;


Der Timer soll im Abstand von 1 Sekunde (also Timer1.Interval 1000) ein neues Bild ins Image1 laden, à la Diashow.
Das Problem ist, dass immer wieder Bilder übersprungen werden.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 04.07.09 13:07 
Versuch es mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var t:integer=6;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  dec(t);
  if t = 0 then
    t := 6
  else
    image1.picture.loadfromfile(Format('%s\bild%.2d.jpg',[ExcludeTrailingPathDelimiter(KompletterPfadzumBild),t]));
end;


Allerdings wird auf diese Weise kein Bild geladen, wenn t in der ersten Zeile 0 wird.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 04.07.09 13:15 
Ist das Absicht im Originalquelltext oben, dass die Reihenfolge der Bilddateien anders ist als das Herunterzählen?
user profile iconWaldkauz hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
t:=t-1;
if t=5 then
 image1.picture.loadfromfile('bild01.jpg');
if t=3 then image1.picture.loadfromfile('bild02.jpg');
if t=2 then image1.picture.loadfromfile('bild03.jpg');
if t=4 then image1.picture.loadfromfile('bild04.jpg');
if t=1 then image1.picture.loadfromfile('bild05.jpg');
if t=0 then t:=6;
end;
R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 28

Win XP Home, Win XP Prof.
D7 Prof., D2006 Arch., BCB2006 Arch.
BeitragVerfasst: Sa 04.07.09 13:34 
Glaube ich nehmlich nicht :D
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 04.07.09 14:12 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Ist das Absicht im Originalquelltext oben, dass die Reihenfolge der Bilddateien anders ist als das Herunterzählen?
user profile iconWaldkauz hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
t:=t-1;
if t=5 then
 image1.picture.loadfromfile('bild01.jpg');
if t=3 then image1.picture.loadfromfile('bild02.jpg');
if t=2 then image1.picture.loadfromfile('bild03.jpg');
if t=4 then image1.picture.loadfromfile('bild04.jpg');
if t=1 then image1.picture.loadfromfile('bild05.jpg');
if t=0 then t:=6;
end;

Was da nicht wirklich eine Rolle spielt ! :wink:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 04.07.09 14:20 
Doch, wenn das den Eindruck verursacht, dass da Bilder "ausgelassen" werden. ;-)
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 04.07.09 15:29 
Relative Dateipfade sind böse und wurden vom Teufel erschaffen :evil: :D

Besser:
ausblenden Delphi-Quelltext
1:
image1.picture.loadfromfile(ExtractFilePath(Application.Exename) + 'bild05.jpg');					

Damit gehst du immer vom Anwendungspfad aus, und nicht vom Arbeitsverzeichnis.

_________________
PROGRAMMER: A device for converting coffee into software.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Sa 04.07.09 16:47 
Also ich hätte das ganze eher so geschrieben (also die Bilder dementsprechend anders durchnummeriert):
ausblenden Delphi-Quelltext
1:
image1.picture.loadfromfile(ExtractFilePath(Application.Exename)+'\bild0'+IntToStr(t)+'.jpg');					

Wobei ich immer nicht so ganz weiß, ob die Funktion ExtractFilePath(Pfad:String):String denn hinter das direkte Mutter-Verzeichnis auch noch ein \ setzt...
...und solange Du nicht das Arbeitsverzeichnis beim Programmstart (also in der aufrufenden Verknüpfung) anders angibst, brauchst Du dieses ja auch gar nicht extra machen!

Wenn Du aber lieber für jeden Integer-Wert Deiner Variable t eine eigene Behandlung hast, dann wäre es doch so einfacher:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
t:=t-1;
case t of
   5: image1.picture.loadfromfile('bild01.jpg');
   4: image1.picture.loadfromfile('bild04.jpg');
   3: image1.picture.loadfromfile('bild02.jpg');
   2: image1.picture.loadfromfile('bild03.jpg');
   1: image1.picture.loadfromfile('bild05.jpg');
   0: t:=6;
   end//der Case-Anweisung

Wobei bei dieser Behandlung dann ja das bild05.jpg doppelt so lange angezeigt wird.


Zuletzt bearbeitet von ffgorcky am Sa 04.07.09 17:01, insgesamt 3-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 04.07.09 16:49 
user profile iconffgorcky hat folgendes geschrieben Zum zitierten Posting springen:
Wobei ich immer nicht so ganz weiß, ob die Funktion ExtractFilePath(Pfad:String):String denn hinter das direkte Mutter-Verzeichnis auch noch ein \ setzt...
Du hast eins zu viel.
ExtractFilePath fügt eins hinzu am Ende, ExtractFileDir macht das selbe und fügt keins hinzu.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 06.07.09 11:29 
Ihr seid alle tolle Programmierer, aber vielleicht solltet ihr euch mal auf die eigentliche Frage konzentrieren. :wink:

Mögliche Ursachen für den Fehler:
1. Die Bilder stehen nicht im richtigen Verzeichnis.
2. Die Variable t wird noch woanders verändert.
3. Die Bilder sind so groß, dass das Laden und Anzeigen länger dauert, als die Timer-Laufzeit.