Autor Beitrag
DXC
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 20.08.05 20:21 
Hallo,

Bei folgendem Quellcode bekomme ich diesen Fehler:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
---------------------------
Benachrichtigung über Debugger-Exception
---------------------------
Im Projekt Project1.exe ist eine Exception der Klasse EAccessViolation mit der Meldung 'Zugriffsverletzung bei Adresse 00454B3E in Modul 'Project1.exe'. Lesen von Adresse 00000044' aufgetreten.
---------------------------
Anhalten   Fortsetzen   Hilfe   
---------------------------


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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure DoTimer (Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  NewTimer: TTimer;
  NewImage: TImage;
  i: Integer;
  ImageArray: array[1..10] of TImage;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned( NewTimer ) then begin
    NewTimer := TTimer.Create (Nil);
    NewTimer.Interval := 20;
    NewTimer.Enabled := True;
    NewTimer.OnTimer := DoTimer;
  end;
  begin
    NewImage := TImage.Create(Nil);
    with NewImage do
      begin
      Top := 144;
      Left := 8;
      Picture.LoadFromFile('xxx.bmp');
      Parent := Form1;
      Name := 'xxx';
      end;
  end;
end;

procedure TForm1.DoTimer(Sender: TObject);
var
  i: integer;
begin
  for i := Low(ImageArray) to High(ImageArray) do
    with ImageArray[i] do
      Top := Top - 3;
end;

end.


:gruebel:


Wäre für jede Antwort dankbar...

MFG
DXC
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 20.08.05 20:27 
ich sehe nirgends, wo du die 10images des array erzeugst. Wenn du im Timereigenis darauf zugreifst, muß es scheppern.

mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 20.08.05 20:42 
So?

ausblenden Delphi-Quelltext
1:
ImageArray: array[min..max] of TImage;					


Funktioniert aber auch nicht... :gruebel:

MFG
DXC
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 20.08.05 20:49 
öhhmm, weißt du überhaupt, was du tust?

du hast doch nirgend die images erstellt, das array alleine reicht nicht, du muß jedes image in dem array erst per create erzeugen, wie du es bei newimage getan hast.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
    for i:=1 to 10 do
      begin
        ImageArray[i] := TImage.Create(Nil);  
        with ImageArray[i] do  
          begin  
            Top := 144;  
            Left := 8;  
            Picture.LoadFromFile('xxx.bmp');  
            Parent := Form1;  
            Name := 'xxx'+inttostr(i);  
         end; 
      end;

achso: und erzeugen mußt du es vor dem Timer. bei programm ende alle wieder mit free freigeben.

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 20.08.05 21:03 
Ok, Danke nur wenn ich dann das zweite mal auf den Button klicke dann bleibt das alte Bild stehen, kann ich das noch ändern ?

MFG
DXC

P.s Hab etz mal 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:
64:
65:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure DoTimer (Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  NewTimer: TTimer;
  NewImage: TImage;
  i: Integer;
  ImageArray: array[1..10] of TImage;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned( NewTimer ) then begin
    NewTimer := TTimer.Create (Nil);
    NewTimer.Interval := 20;
    NewTimer.Enabled := True;
    NewTimer.OnTimer := DoTimer;
  end;
  begin
    for i:=1 to 10 do
      begin
        ImageArray[i] := TImage.Create(Nil);  
        with ImageArray[i] do  
          begin  
            Top := 144;  
            Left := 8;  
            Picture.LoadFromFile('xxx.bmp');  
            Parent := Form1;  
            Name := 'xxx'+inttostr(i);  
         end; 
      end;
    end;
end;

procedure TForm1.DoTimer(Sender: TObject);
var
  i: integer;
begin
  for i := Low(ImageArray) to High(ImageArray) do
    with ImageArray[i] do
      Top := Top - 3;
end;

end.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 20.08.05 21:43 
Ich verstehe das Problem nicht - was soll sich denn ändern? Welches Bild soll sich ändern? Pass auf: Es gibt da eine Prozedur, die nennt sich Form1Create und diese eignet sich vorzüglich um Objekte, die sowieso die ganze Zeit existieren, zu erzeigen. mach das doch lieber dort, dann hast du nicht das Problem, dass du die Komponenten evtl. 2 mal erzeugst, was ja nicht nötig ist.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: So 21.08.05 11:33 
Hallo,

Also mein Problem ist folgendes:

Wenn ich 1-Mal auf den Button klicke dann wird ja ein Bild (xxx.bmp) erstellt und verschiebt sich durch den erstellten Timer nach oben.
So, wenn ich aber dann das 2-Mal auf den Button klicke dann bleibt DAS ERSTE BILD STEHEN und es wird ein neues Bild erzeugt was sich dann nach oben bewegt...usw.

Mein Hauptsächliches Problem ist:

1. Es soll so sein dass 2-Mal auf den Button geklickt wird, nur dann soll sich das 1-ste und das 2-te bild nach oben bewegen (das erste soll nicht stehen bleiben!)

Bitte, bitte helft mir .... :crying: :flehan:

MFG
DXC
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 21.08.05 11:44 
das steht alles schon da, lies Dir die Antwort von Jayeff nochmal genau durch.

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 11:52 
also ich hab genau das projekt übernommen und habe nicht das problem
wenn dann mach einfach
ausblenden Delphi-Quelltext
1:
if ImageArray[i]=ImageArray[1] then ImageArray[1].Picture.Bitmap:=nil;					

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 11:56 
ach noch was!!
warum ladest du 10 mal das selbe bild????
mach das doch so!!
ausblenden 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:
procedure TForm1.Button1Click(Sender: TObject);
var bmp:TBitmap;
begin
  if not Assigned( NewTimer ) then begin
    NewTimer := TTimer.Create (Nil);
    NewTimer.Interval := 20;
    NewTimer.Enabled := True;
    NewTimer.OnTimer := DoTimer;
  end;
  begin
    bmp:=TBitmap.Create;
    bmp.LoadFromFile('xxx.bmp');
    for i:=1 to 10 do
      begin
        ImageArray[i] := TImage.Create(Nil);
        with ImageArray[i] do
          begin
            Top := 144;
            Left := 8;
            Picture.Bitmap:=bmp;
            Parent := Form1;
            Name := 'xxx'+inttostr(i);
         end;
      end;
    bmp.free;
    end;
end;

zudem würd ich bei oncreate doublebuffered auf true setzen!

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: So 21.08.05 14:35 
Hallo,

erstmals Danke für eueren ganzen Antworten und für eure Mühe mir zu helfen...

Momentan sieht das ganze bei mir so 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:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DoTimer (Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  NewTimer: TTimer;
  NewImage: TImage;
  i: Integer;
  ImageArray: array[1..10] of TImage;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var bmp:TBitmap;
begin
  if not Assigned( NewTimer ) then begin
    NewTimer := TTimer.Create (Nil);
    NewTimer.Interval := 20;
    NewTimer.Enabled := True;
    NewTimer.OnTimer := DoTimer;
  end;
  begin
    bmp:=TBitmap.Create;
    bmp.LoadFromFile('xxx.bmp');
    for i:=1 to 10 do
      begin
        ImageArray[i] := TImage.Create(Nil);
        with ImageArray[i] do
          begin
            Top := 144;
            Left := 8;
            Picture.Bitmap:=bmp;
            Parent := Form1;
            Name := 'xxx'+inttostr(i);
         end;
      end;
    bmp.free;
    end;
end;

procedure TForm1.DoTimer(Sender: TObject);
var
  i: integer;
begin
  for i := Low(ImageArray) to High(ImageArray) do
    with ImageArray[i] do
      Top := Top - 3;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
end;

end.


Und beim starten kommt nur folgende Warnung:

ausblenden Quelltext
1:
[Warnung] Unit1.pas(45): W1019 FOR-Schleifenvariable muss eine einfache lokale Variable sein					


Aber immerhin wenn ich dann das 2-te mal den Button drücke dann bleibt das erste Bild stehen...(es sollen sich aber beide weiterbewegen).
Freue mich immernoch auf jede Antwort...

MFG
DXC
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 21.08.05 15:08 
Die Schleifenvariable 'i' ist nicht lokal in Button1Click deklariert, daher die warnung.
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 15:12 
also wenn ich das richtig sehe hast du global die variable i deklariert und später nochmal
bei
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.DoTimer(Sender: TObject);
var
  i: integer;//hier! nimm lieber einen anderen buchstaben sonst kann es probs geben! also f oder was weiß ich
begin
  for i := Low(ImageArray) to High(ImageArray) do
    with ImageArray[i] do
      Top := Top - 3;
end;

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 15:26 
jo ich bins nomal 8)
ich wollt nur mal fragen was du genau machen willst :?:
wenn ich das richtig sehe willst nur das ein bild nach oben wandert oder???
mdf huhn

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: So 21.08.05 16:02 
Hallo,

:autsch: Es soll so sein:

Wenn ich jetzt einmal auf den Button klicke dann soll ja ein Bild (angenommen Bild1) erstellt werden, und natürlich ein Timer (angenommen Timer1). So nun bewegt sich Bild1 über den Timer1 nach oben.

Wenn ich jet aber ein 2-Tes mal auf dem Button klicke dann wird ja nochmal ein Bild erstellt (angenommen Bild2) und auch ein Timer (angenommen Timer 2). So nun bewegt sich Bild2 über den Timer2 nach oben.

Mein Problem wenn sich jetzt bild2 nach oben bewegt dann bleibt bild 1 stehen und genau dass soll NICHT passieren !!!

MFG
DXC ... ist am ende :crying:
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 16:53 
Ist ja auch klar da du nicht dann 2 Timer hast sondern noch immer nur einen!
Du hast ihn nur ein 2 mal erstellt!
Reicht es eventuell nicht einfach aus wenn du nur 1 bild und 1 timer hast und einfach ein neues bild ladest und es nocheinmal laufen lässt?

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: So 21.08.05 17:05 
Hallo,

Kannst du mir bitte sagen wie so etwas mit einem 2 Timer gehen soll ?
Wäre Dankbar...

MFG
DXC
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: So 21.08.05 17:40 
vielleicht so ähnlich wie bei deinem image, also mit einem array.
ich würde es aber nicht so machen sondern alles unter einem timer laufen lassen.
ich hab nomal deinen quell überarbeitet und kommentiert:
(is ausm kopf ohne delphi!)
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:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DoTimer (Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  NewTimer: TTimer;
  NewImage: TImage;
  i: Integer;
  ImageArray: array[1..10] of TImage;
  laufen:integer;

implementation

{$R *.dfm}

//erst erstellen und laufen lassen
procedure TForm1.FormCreate(Sender: TObject);
var bmp:TBitmap;
begin
laufen:=0;
  if not Assigned( NewTimer ) then begin
    NewTimer := TTimer.Create (Nil);
    NewTimer.Interval := 20;
    NewTimer.Enabled := True;
    NewTimer.OnTimer := DoTimer;
  end;
    bmp:=TBitmap.Create;
    bmp.LoadFromFile('xxx.bmp');
    for i:=1 to 10 do
      begin
        ImageArray[i] := TImage.Create(Nil);
        with ImageArray[i] do
          begin
            Top := 144;
            Left := 8;
            Picture.Bitmap:=bmp;
            Parent := Form1;
            Name := 'xxx'+inttostr(i);
         end;
      end;
    bmp.free;
end;

//festlegen wieviel bilder laufen sollen
procedure TForm1.Button1Click(Sender: TObject);
begin
laufen:=laufen+1;
end;

procedure TForm1.DoTimer(Sender: TObject);
var
  z: integer;
begin
if laufen=0 then exit;
for z:=1 to laufen do
  ImageArray[z].top:=ImageArray[z].top-3;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
end;

end.

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: So 21.08.05 20:09 
Cool, Danke Funzt :wink: