Autor Beitrag
Ottchen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43



BeitragVerfasst: Sa 08.03.03 19:46 
Mit meinem Linienprogramm komme ich einfach nicht weiter.

Es soll folgendes können:
- Beim ersten Klick auf die Zeichenoberfläche soll ein Punkt
mit seinen Koordinaten angezeigt werden (das habe ich ja noch hinbekommen...).
- Nach dem zweiten Klick soll ein zweiter Punkt gesetzt und die Gerade zwischen den beiden Punkten
gezeichnet werden (z.B. mit LineTo)

Um das zu realisieren nimmt man also das OnMouseDown-Ereignis der Image-Komponente.
Wie verklickere ich aber Delphi, wann der zweite Klick erfolgt ist? Das mit einer
Boolean-Variable als Schalter ist mir nicht geglückt. Man muss sich ja auch die Koordinaten des ersten Punktes mittels
Varaiablen merken (vx1,vx2,vy1,vy2).

Aber wie klappt das mit der Boolean-Variable?


Danke! Ottchen :--((


Hier mein wieder stark gekürzter Quelltext...


ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var vx1, vx2,                   //x-Koordinaten
    vy1, vy2 : integer;         //y-Koordinaten


begin
  with Image1.Canvas do
    begin
       vx1:=x;
       vy1:=y;
       TextOut(vx1,vy1,' '+IntToStr(vx1)+','+IntToStr(vy1)); //Koordinaten ausgeben
       Pixels[x,y]:=clNavy;   //Punkt setzen
    end;

end;

_________________
See you.


Zuletzt bearbeitet von Ottchen am So 09.03.03 19:36, insgesamt 1-mal bearbeitet
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Sa 08.03.03 19:49 
Hi,

(Wer is Liste?) So geht es:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  Click2nd: Boolean = false;

procedure TImage.OnMouseDown(...);
begin
  if not Click2nd then
    Image1.Canvas.MoveTo(X,Y)
  else
    Image1.Canvas.LineTo(X,Y);
  Click2nd:=NOT Click2nd;
end;


Au'revoir,
Aya

_________________
Aya
I aim for my endless dreams and I know they will come true!
Ottchen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43



BeitragVerfasst: Sa 08.03.03 20:32 
Titel: Funktioniert nicht, AYA
Hier mein Quelltext:

ausblenden volle Höhe 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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    BitBtn_Ende: TBitBtn;
    procedure BitBtn_EndeClick(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

var schalter :boolean=false;       //entscheidet, ob linke Maustaste gedrückt wurde oder nicht

{$R *.dfm}

procedure TForm1.BitBtn_EndeClick(Sender: TObject);
begin
  close
end;


procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var vx1, vx2,                   //x-Koordinaten
    vy1, vy2 : integer;         //y-Koordinaten

begin
  if NOT schalter then
   begin
     with Image1.Canvas do
        begin
          vx1:=x;
          vy1:=y;
          TextOut(vx1,vy1,' '+IntToStr(vx1)+','+IntToStr(vy1)); //Koordinaten ausgeben
          Pixels[vx1,vy1]:=clNavy;   //Punkte setzen
          MoveTo(vx1,vy1);
         end;
   end
   else
    begin
      with Image1.Canvas do
        begin
          vx2:=x;
          vy2:=y;
          TextOut(vx2,vy2,' '+IntToStr(vx2)+','+IntToStr(vy2)); //Koordinaten ausgeben
          Pixels[vx2,vy2]:=clNavy;   //Punkte setzen
          LineTo(vx2,vy2);
          schalter:=NOT schalter;
        end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Image1.Canvas
end;

end.

_________________
See you.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Sa 08.03.03 20:40 
Titel: Re: Funktioniert nicht, AYA
Ottchen hat folgendes geschrieben:
Hier mein Quelltext:

mhh... ja, soll ich damit jetzt irgendwas machen, oder willst du damit nur sagen das alles funktioniert? :roll:

_________________
Aya
I aim for my endless dreams and I know they will come true!
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: Sa 08.03.03 23:12 
hinter dem
ausblenden Quelltext
1:
if not schalter then					

muss auch noch ein
ausblenden Quelltext
1:
schalter:=not schalter					
Ottchen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43



BeitragVerfasst: So 09.03.03 19:38 
Titel: klappt nicht...
Aya, das Programm funktioniert nicht.

Fiji-Fighter,

wenn ich hinter den Code deinen Vorschlag setze, zeichnet das Programm nicht eine Linie
zwischen den gesetzten Punkten, sondern eine waagerechte Linie über den zuletzt gesetzten Punkt.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
begin 
  if NOT schalter then 
   begin 
     schalter:=not schalter
     with Image1.Canvas do 
       .
       .
       .


Und welche Bewandnis hat das mit der Boolean-Variable?

Habt ihr noch eine Idee?

PS: Einfach mal ein Image auf das Formular bringen und auf das OnMouseDown-Ereignis des Images reagieren
und "meinen" fehlerhaften Quelltext hineinkopieren. Das Ergebnis ist echt merkwürdig...

Ottchen

_________________
See you.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 09.03.03 20:40 
Hi,

so geht es..:

ausblenden volle Höhe 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, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  schalter :boolean=false;
  vx1, vx2,                   //x-Koordinaten
  vy1, vy2 : integer;         //y-Koordinaten

implementation

{$R *.dfm}

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if NOT schalter then
   begin
     with Image1.Canvas do
        begin
          vx1:=x;
          vy1:=y;
          TextOut(vx1,vy1,' '+IntToStr(vx1)+','+IntToStr(vy1)); //Koordinaten ausgeben
          Pixels[vx1,vy1]:=clNavy;   //Punkte setzen 
          MoveTo(vx1,vy1);
         end;
   end
   else
    begin
      with Image1.Canvas do
        begin
          vx2:=x;
          vy2:=y;
          TextOut(vx2,vy2,' '+IntToStr(vx2)+','+IntToStr(vy2)); //Koordinaten ausgeben
          Pixels[vx2,vy2]:=clNavy;   //Punkte setzen
          MoveTo(vx1,vy1);
          LineTo(vx2,vy2);
        end;
    end;
  schalter:=NOT schalter;
end;

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

end.


Au'revoir,
Aya

_________________
Aya
I aim for my endless dreams and I know they will come true!
Ottchen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43



BeitragVerfasst: Do 13.03.03 22:01 
Titel: Es klappt!!
Hallo Aya,

vielen Dank für deine Mühe. Das Programm läuft 1a!!

Aber das mit dem Schalter und NOT Schalter kapiere ich noch nicht so richtig. Kannste mir da mal noch einen Tipp geben?

Oben definierst du den Schalter auf false. So müsste NOT schalter doch true bedeuten, oder? Wenn ich aber dann statt if NOT schalter setzte: if schalter:=true funktioniert es nicht...

Ottchen

_________________
See you.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Fr 14.03.03 18:50 
Hi,

war seit Montag weg, deswegen meine antwort erst jetzt... :)

Also...

ausblenden Quelltext
1:
MyBool: Boolean = false					

Heißt, das der "Schalter" MyBool nicht gesetzt ist.

Bei der IF-Abfrage:
ausblenden Quelltext
1:
if MyBool then...					

ist es so.. "Wenn MyBool True ist..." oder "Wenn der Schalter gesetzt ist..."

Bei:
ausblenden Quelltext
1:
if NOT MyBool then...					

halt "Wenn mein Schalter NICHT gesetzt ist..." also wenn MyBool = false

und mit:
ausblenden Quelltext
1:
MyBool:=NOT MyBool;					

Wird einfach aus true ein false, und aus false ein true :)

Au'revoir,
Aya

_________________
Aya
I aim for my endless dreams and I know they will come true!
Ottchen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 43



BeitragVerfasst: Sa 15.03.03 09:00 
Titel: Einfach nur Logik
Ja das ist einfach nur Logik. Man kann also auch mit true und false arbeiten statt mit NOT.

Super. Vielen Dank!

Jetzt bin ich ein ganzes Stück weiter.


Vielen Dank!

_________________
See you.