Autor Beitrag
Slice
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Sa 08.11.08 15:28 
So ich habe jetzt folgendes Problem:

Ich möchte eine Linie in eine Painbox zeichnen,bei der man nur die geradengleichung y=m*x+b brauch.
Um es nochmal genauer zu sagen, es gibt 2 Edit-Felder und in das 1. schreibt man die Steigung (m) und in das 2. die Achsenhöhe(b). Wenn man dann auf den Button klickt, soll eine Linie mit diesen Werten in die Paintbox gezeichnet werden. Leider weiß ich da net weiter.
Hier mal alles was ich bisher hab(nicht viel):

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

interface

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

type
Tlinie= record
  x1,y1:integer;
  x2,y2:integer;
    TForm1 = class(TForm)
     PaintBox1: TPaintBox;
     Edit1: TEdit;
     Edit2: TEdit;
     Button1: TButton;
     procedure FormCreate(Sender: TObject);
     procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    function Gerade (m:integer,b:integer):single;
  end;

var
  Form1: TForm1;
  a:integer;
  linie: Tlinie;

implementation

{$R *.DFM}
function TForm1.Gerade;
 begin
  result:=m*x+b;
  end;

procedure TForm1.FormCreate(Sender: TObject); //Koordinatensytem
begin
With Paintbox1.Canvas do
MoveTo(200,0);
LineTo(200,400);
MoveTo(0,200);
LineTo(400,200);
end;
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 08.11.08 16:23 
Hi :)

Da brauchst du wohl ein paar Parameter bei deiner Geradenfunktion ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function TForm1.Gerade(m, x, b: Integer);
begin
  result := m * x + b;
end;


Jetzt brauchst du ja Start- und Endpunkt. Dazu einfach Gerade(m, 0, b) und Gerade(m, width(Paintbox1), b) nehmen und jetzt müsste es gehen ;)

Das Zeichnen solltest du bei einer Paintbox unbedingt ins OnPaint-Ereignis packen(mal im Object-Inspector bei der PBox unter Events schauen und auf das leere Feld bei "OnPaint" einen Doppelklick machen).

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 09.11.08 12:56 
Zitat:
Dazu einfach Gerade(m, 0, b) und Gerade(m, width(Paintbox1), b) nehmen


das versteh ich net ganz. hab das jetzt mal so gemacht aber geht irgendwie net:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
begin
Paintbox1.Canvas.MoveTo(Gerade(StrToInt(Edit1.Text),0,StrToInt(Edit2.Text));
Paintbox1.Canvas.LineTo(Gerade(StrToInt(Edit1.Text),400,StrToInt(Edit2.Text)));
end;

end.


bekomm immer angezeigt: Inkompatible Typen: 'Integer' und 'Single'
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 09.11.08 13:36 
MoveTo und LineTo bekommen Koordinaten, erst X, dann Y als Integer. Deine Funktion hast du aber so deklariert, dass sie einen Singlewert zurückgibt. Das musst du mit Round auf einen Integerwert runden.

Im Moment versuchst du auch nur den Y-Wert anzugeben, das kann ja nicht gehen ;-).
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 09.11.08 16:15 
wenn ich jetzt wüsste wie das geht^^ hab noch net so viel ahnung und das mit dem round kenn ich net !?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 09.11.08 16:56 
Ändere einfach den Typ des Rückgabewerts auf Integer, das reicht auch:

ausblenden Delphi-Quelltext
 
24:
{ ... }
    function Gerade (m:integer,b:integer): Integer;
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 09.11.08 17:44 
klappt net mit dem integer. bekomm jetzt immer "nicht genügend Parameter" angezeigt.

sieht jetzt 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:
  public
    { Public-Deklarationen }
    function Gerade (m,x,b:integer):integer;
  end;

var
  Form1: TForm1;
  linie: Tlinie;
  c: integer;

implementation

{$R *.DFM}
function TForm1.Gerade;
begin
  result := m * x + b;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
With Paintbox1.Canvas do
 begin
  MoveTo(200,0);
   LineTo(200,400);
    MoveTo(0,200);
     LineTo(400,200);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Paintbox1.Canvas.MoveTo(Gerade(StrToInt(Edit1.Text),0,StrToInt(Edit2.Text));
Paintbox1.Canvas.LineTo(Gerade(StrToInt(Edit1.Text),400,StrToInt(Edit2.Text)));
end;

end.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 09.11.08 18:08 
user profile iconSlice hat folgendes geschrieben Zum zitierten Posting springen:
klappt net mit dem integer. bekomm jetzt immer "nicht genügend Parameter" angezeigt.
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
MoveTo und LineTo bekommen Koordinaten, erst X, dann Y als Integer. [...]
Im Moment versuchst du auch nur den Y-Wert anzugeben, das kann ja nicht gehen ;-).


Übrigens fehlen da auch noch Klammern... 4 Klammern auf bei MoveTo / LineTo und nur 3 zu.
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 09.11.08 19:15 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconSlice hat folgendes geschrieben Zum zitierten Posting springen:
klappt net mit dem integer. bekomm jetzt immer "nicht genügend Parameter" angezeigt.
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
MoveTo und LineTo bekommen Koordinaten, erst X, dann Y als Integer. [...]
Im Moment versuchst du auch nur den Y-Wert anzugeben, das kann ja nicht gehen ;-).


Übrigens fehlen da auch noch Klammern... 4 Klammern auf bei MoveTo / LineTo und nur 3 zu.

hab ich gemacht aber hat nix geändert. naja jetzt is eh zu spät. brauch es morgen früh -.-
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 09.11.08 19:38 
user profile iconSlice hat folgendes geschrieben Zum zitierten Posting springen:
hab ich gemacht aber hat nix geändert.

Poste mal deinen bisherigen Quelltext, dann können wir den Fehler vielleicht besser erkennen.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 09.11.08 19:45 
Dass es dringend ist, hättest du ruhig früher erwähnen können ;)

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mo 10.11.08 10:48 
könnt mir ja trotzdem noch weiterhelfen^^ also hier mal der 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:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
unit Unit1;

interface

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

type
Tlinie= record
   x1,y1:integer;
   x2,y2:integer;
   end;
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    PaintBox1: TPaintBox;
    procedure PaintBox1Paint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    function Gerade (m,x,b:integer):integer;
  end;

var
  Form1: TForm1;
  linie: Tlinie;
  c: integer;
  x:integer;

implementation

{$R *.DFM}
function TForm1.Gerade;
begin
  result := m * x + b;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
With Paintbox1.Canvas do
 begin
  MoveTo(200,0);
   LineTo(200,400);
    MoveTo(0,200);
     LineTo(400,200);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Paintbox1.Canvas.MoveTo(Gerade((StrToInt(Edit1.Text)),0,(StrToInt(Edit2.Text)));
Paintbox1.Canvas.LineTo(Gerade((StrToInt(Edit1.Text)),400,StrToInt(Edit2.Text)));
end;

end.
Slice Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 11.11.08 21:34 
hab noch bis freitag zeit dafür also hat noch jemand nen vorschlag??
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 11.11.08 21:48 
Schauen wir uns mal eine etwas unüblich formatierte Version der Zeile 55 an (Zeile 56 verhält sich analog dazu):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Paintbox1.Canvas.MoveTo(
  Gerade(
    (
      StrToInt(
        Edit1.Text
      )
    ),
    0,
    (
      StrToInt(
        Edit2.Text
      )
    )
  )
 ;

Zwei Dinge sind erkennbar:
  1. Windschutzklammern™ (gehighlightet). Ist aber nicht schlimm.
  2. Die Parameterliste ist nicht vollständig: Am Schluss fehlt eine Klammer zu (gehighlightetes Leerzeichen). Aber halt: Nicht nur dass, sondern auch der komplette Y-Wert, wie schon erwähnt wurde.


Hier die korrigierte Version:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Paintbox1.Canvas.MoveTo(
  Gerade(
    StrToInt(
      Edit1.Text
    ),
    0,
    StrToInt(
      Edit2.Text
    ),
  ),
  0
);