Autor Beitrag
Hochhäusl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Do 17.12.09 19:56 
Hallo,

ich erstelle eine TImage und brauche ein OnClick-Ereignis:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
Bild:=TImage.Create(Form1);
Bild.Parent:= Form1;

Bild.OnClick:=BildClick;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.BildClick(Sender: TObject);
begin
Bild.Canvas.Ellipse(x1,y1,x2,y2);
end;


Das OnClick- Ereignis funktioniert auch, solange ich nicht versuche etwas zu Zeichnen.

Weiß Jemand wo mein Fehler liegt?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 17.12.09 20:17 
Hallo,

funktioniert einwandfrei.

Wo/wie ist die Variable Bild deklariert?

Was bedeutet "funktioniert nicht", wird das Ereignis nicht ausgelöst, wird nichts gezeichnet, gibt es eine Fehlermeldung ...?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Do 17.12.09 20:28 
Ich bekomme eine Fehlermeldung:

Zitat:
Access violation at address 0042.. in module project.exe.
Read of address 0002C



Die Variable habe ich in der Unit deklariert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  Form1: TForm1;
  Bild: TBitmap;

implementation

{$R *.dfm}
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 17.12.09 20:29 
Hm, was ist denn "Bild" denn nun? Ein TImage oder ein TBitmap? Da geht wohl was durcheinander...

_________________
We are, we were and will not be.
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Do 17.12.09 20:32 
Stimmt, das habe ich wohl übersehen. :(

Habe jetz
ausblenden Delphi-Quelltext
1:
Bild: TImage;					


Ändert aber nichts am Problem.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 17.12.09 20:37 
Hm, ist Bild vielleicht nochmal als lokale Variable deklariert, in der Prozedur, wo das erstellt wird? Denn sonst hätte der Code vorher gar nicht kompilieren dürfen...

Zeig aber mal am besten den ganzen Code - so ist das nur ne Rumraterei. ;-)

_________________
We are, we were and will not be.
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Do 17.12.09 23:01 
Hier der ganze Quelltext:

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

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button2: TButton;
    procedure BildClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Bild: TImage;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
var Bild: TImage;
begin
Bild:=TImage.Create(Form1);
Bild.Parent:= Form1;
Bild.Top:=10;
Bild.Left:=10;
Bild.Width := Image1.Width;
Bild.Height := Image1.Height;
Bild.OnClick:=BildClick;
end;

procedure TForm1.BildClick(Sender: TObject);
begin
Bild.Canvas.Ellipse(10,10,50,50);
end;

end.
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Do 17.12.09 23:06 
So, jetz hab ich den Fehler gefunden.

Hatte die Variable wirklich noch ein 2tes mal in der Procedure deklariert.
Einfach die Zeile 30 im obigen Code gelöscht, und schon funktioniert.

Danke für die schnelle Hilfe