Autor Beitrag
Ricarda123
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Fr 13.02.09 11:59 
Hey Leute!

ich brauche dringend eure Hilfe. Mein FUnktionsplotter läuft nicht und ich habe jetzt schon mindestens 3 Unterrichtsstunden mit dem Überprüfen verbraucht. Ich weiß nicht, wo mein Fehler liegt! Helft mir doch bitte, ich würde mich sehr darüber freuen!

Hier ist 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:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
unit mParabel;

interface

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

     type
  TForm1 = class(TForm)
    Image1: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    beenden1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Zeichnen1: TMenuItem;
    Lschen1: TMenuItem;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Farbe1: TMenuItem;
    STiftfarbe1: TMenuItem;
    Hintergrund1: TMenuItem;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    GroupBox3: TGroupBox;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Edit4: TEdit;
    Edit5: TEdit;
    TrackBar1: TTrackBar;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    Timer1: TTimer;
    Panel1: TPanel;
    GroupBox4: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    Panel2: TPanel;
    procedure FormActivate(Sender: TObject);
    procedure Zeichnen1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Lschen1Click(Sender: TObject);
    procedure beenden1Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure berechneMittelpunkt;
    procedure zeichneKoordinatensystem;
    procedure Fktzeichnen;

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

  var x0,y0,        //Koordinatenursprung
      xa,xb,       //Intervall
      ya,yb,       //Intervall
      imBreite,imHoehe,   //Breite, Hoehe des Images
      StiftFarbe,
      Einheit,i,strichlaenge:Integer;   //Abmessungen des Image
      //bLinie,             //Linienbreite
      //FktKennung:Integer;    //Ausgewählte Funktion
      //HintergrundFarbe:TColor;
      c,a,b,x,y,m,n:double;        //Parameter, Variablen

procedure TForm1.berechneMittelpunkt;   //Koordinatenurpsrung
begin
  x0:=round(image1.width/2);
  y0:=round(image1.height/2);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
    imBreite:=Image1.Width;    //Breite u. Höhe des Bildes in Pixel
    imHoehe:=Image1.Height;
    berechneMittelpunkt;
    xa:=round(-x0); xb:=round(x0);       //Definitionsbereich {x}  : Anfang xa bis Ende xb
    ya:=round(-x0); yb:=round(x0);       //Wertebereich {y}    : Anfang ya bis Ende yb
    Einheit:=Trackbar1.Position;
    StiftFarbe:=clBlue;
end;

procedure TForm1.zeichneKoordinatensystem;
begin
einheit:=trackbar1.position;
Strichlaenge:=round(Einheit/9);
with Image1.Canvas do begin
  pen.color:=clwhite;
  brush.color:=clwhite;
  rectangle(0,0,width,height);
  Brush.Color:=clBlue;
  Pen.Color:=clblack;
  MoveTo(0,y0); LineTo(imBreite,y0);    //x-Achse
  MoveTo(x0,0); LineTo(x0,imHoehe);    //y-Achse
//Striche:
i:=0;
  while i<imBreite do begin
  MoveTo(x0 - i,y0 - StrichLaenge);LineTo(x0-i,y0 + StrichLaenge);
  MoveTo(x0 + i,y0 - StrichLaenge);LineTo(x0+i,y0 + StrichLaenge);
  MoveTo(x0 - StrichLaenge,y0 - i);LineTo(x0+StrichLaenge,y0 - i);
  MoveTo(x0 - StrichLaenge,y0 + i);LineTo(x0+StrichLaenge,y0 + i);
  i:= i + Einheit;
end;
end;
end;

procedure TForm1.Fktzeichnen;
begin
zeichneKoordinatensystem;
// Parameter:
c:=strtofloat(edit3.text);
a:=strtofloat(edit1.Text);
b:=strtofloat(edit2.Text);
m:=strtofloat(edit4.text);
n:=strtofloat(edit5.Text);

with Image1.canvas do begin

  if (radiobutton1.checked) then  //lineare Funktion
  begin
   groupbox3.visible:=true;
   groupbox1.Visible:=false;
   Pen.Color:=clblue;
   x:=xa;              //lege x  auf Intervallanfang
   y:=m*x+n;              //berechne Funktionswert y
   moveTo(x0+round(x*Einheit),y0-round(y*Einheit)); //setze Pixel-Cursor auf ersten Punkt (x,y)
   repeat
   x:=x+1/Einheit;      //Argument x erhöhen um 1 Teil von dx (1 Pixel)
   y:=m*x+n;              //berechne Funktionswert y
   lineTo(x0+round(x*Einheit),y0-round(y*Einheit));    //zeichne Linie zu nächstem Punkt (x,y)
   until x>xb;              //wiederhole bis Intervallende erreicht
  end;

  if (RadioButton2.checked) then   //quadrat. Funktion
  begin
   groupbox3.visible:=false;
   groupbox1.visible:=true;
   Pen.Color:=clblue;
   x:=xa;              //lege x  auf Intervallanfang
   y:=a*x*x+b*x+c;              //berechne Funktionswert y
   moveTo(x0+round(x*Einheit),y0-round(y*Einheit)); //setze Pixel-Cursor auf ersten Punkt (x,y)
   repeat
   x:=x+1/Einheit;      //Argument x erhöhen um 1 Teil von dx (1 Pixel)
   y:=a*x*x+b*x+c;              //berechne Funktionswert y
   lineTo(x0+round(x*Einheit),y0-round(y*Einheit));    //zeichne Linie zu nächstem Punkt (x,y)
   until x>xb;              //wiederhole bis Intervallende erreicht
  end;
end;
end;

procedure TForm1.Zeichnen1Click(Sender: TObject);
begin
Fktzeichnen;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Image1.Canvas do begin
   Pen.Color:=clwhite;
   Pen.Style:=psSolid;
   Pen.Width:=1;
  // Brush.Color:=Hintergrundfarbe;
   Brush.Style:=bsSolid ;
   Rectangle(0,0,width,height);
  end;
  zeichneKoordinatensystem;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
  with Image1.Canvas do begin
   Pen.Color:=clwhite;
   Pen.Style:=psSolid;
   Brush.Color:=clwhite;
   Rectangle(0,0,width,height);
  end;
  zeichneKoordinatensystem;
end;

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

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
fktzeichnen;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
<div class="syntaxContainer">  <div class="syntaxSelect">    <a class="genmed" style="text-decoration: none" href="javascript:selectAll(54935710)">markieren</a>  </div>  <div class="syntaxTitle genmed">        <a style="text-decoration: none" href="javascript:toggleCode(54935710)">            <span  id="minusFor54935710"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_hide.png" border="0" alt="ausblenden" title="ausblenden"/></span>            <span style="display: none;" id="plusFor54935710"><img class="codecollapse crispscaling" align="top" src="./graphics/bbcode/code_show.png" border="0" alt="anzeigen" title="anzeigen"/></span>        </a>                <b>Delphi-Quelltext</b>        <span class="copyright" style="display: none" id="hintFor54935710">                       </span>  </div>  <div id="code54935710" class="syntax" style=" ">    <table cellspacing="0" cellpadding="0">      <tr>        <td valign="top" style="text-align: right; padding-right: 3px; border: #DBE4EB solid; border-width: 0px 1px 0px 0px;">          <pre>1:
</pre>        </td>        <td valign="top" style="width: 100%; padding-left: 3px;">          <pre class="sourcecode">Fktzeichnen;          </pre>        </td>      </tr>    </table>  </div></div>
end;

end.



Moderiert von user profile iconKha: Delphi-Tags hinzugefügt, unnötige Formatierungen entfernt
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: Fr 13.02.09 12:13 
Verrätst du uns vielleicht auch nocht, was da genau "nicht geht"?

_________________
PROGRAMMER: A device for converting coffee into software.
Ricarda123 Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Fr 13.02.09 12:16 
Oh sorry, na klar, das fehlt.
Naja, also das programm startet ganz normal, aber sobald ich auf Zeichnen, Radiobutton1 oder Radiobutton2 klicke funktioniert gar nichts mehr. Ich vermute einen Fehler bei Fktzeichnen oder zeichne Koordinatensystem, weiß es aber eben nicht genau!
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Fr 13.02.09 13:03 
Formatiere als erstes mal deinen Quelltext, das erhöht die Lesbarkeit! Heißt:

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:
procedure ...;
var
  a: datentyp;
  b: datentyp;
begin
  ...
  ...
  if a = b then
    ...;
  if a = b then
  begin
    ...
    ...
  end;
  a := b;
  // Kommentar
  b := c; // Kommentar

  case b of
    a: ...
    b: ...
    c: ...
    else: ...
  end;
end;


Also Befehle auf gleicher Ebene sind auch gleich einzurücken. So dass man eine Struktur erkennen kann. Begin und End sind ebenfalls gleich einzurücken.

Weiterhin solltest du mal i ausgeben lassen. Ich habe schon eine Vermutung. Ich habe aber auch keine Lust, das jetzt zu prüfen, ohne Formular und weiteres. Am besten du packst mal deine Dateien (DPR, DFM, PAS) und postest es (-> Dateianhang hinzufügen).

Oder du findest es selbst heraus. Zumindest nehme ich mal folgende Stelle als Fehler an:

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:
  if (radiobutton1.checked) then  //lineare Funktion
  begin
   groupbox3.visible:=true;
   groupbox1.Visible:=false;
   Pen.Color:=clblue;
   x:=xa;              //lege x  auf Intervallanfang
   y:=m*x+n;              //berechne Funktionswert y
   moveTo(x0+round(x*Einheit),y0-round(y*Einheit)); //setze Pixel-Cursor auf ersten Punkt (x,y)
   repeat
   x:=x+1/Einheit;      //Argument x erhöhen um 1 Teil von dx (1 Pixel)
   y:=m*x+n;              //berechne Funktionswert y
   lineTo(x0+round(x*Einheit),y0-round(y*Einheit));    //zeichne Linie zu nächstem Punkt (x,y)
   until x>xb;              //wiederhole bis Intervallende erreicht
  end;

  if (RadioButton2.checked) then   //quadrat. Funktion
  begin
   groupbox3.visible:=false;
   groupbox1.visible:=true;
   Pen.Color:=clblue;
   x:=xa;              //lege x  auf Intervallanfang
   y:=a*x*x+b*x+c;              //berechne Funktionswert y
   moveTo(x0+round(x*Einheit),y0-round(y*Einheit)); //setze Pixel-Cursor auf ersten Punkt (x,y)
   repeat
   x:=x+1/Einheit;      //Argument x erhöhen um 1 Teil von dx (1 Pixel)
   y:=a*x*x+b*x+c;              //berechne Funktionswert y
   lineTo(x0+round(x*Einheit),y0-round(y*Einheit));    //zeichne Linie zu nächstem Punkt (x,y)
   until x>xb;              //wiederhole bis Intervallende erreicht
  end;
end;
end;

procedure TForm1.Zeichnen1Click(Sender: TObject);
begin
Fktzeichnen;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Image1.Canvas do begin
   Pen.Color:=clwhite;
   Pen.Style:=psSolid;
   Pen.Width:=1;
  // Brush.Color:=Hintergrundfarbe;
   Brush.Style:=bsSolid ;
   Rectangle(0,0,width,height);
  end;
  zeichneKoordinatensystem;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
  with Image1.Canvas do begin
   Pen.Color:=clwhite;
   Pen.Style:=psSolid;
   Brush.Color:=clwhite;
   Rectangle(0,0,width,height);
  end;
  zeichneKoordinatensystem;
end;

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

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
fktzeichnen;
end;


oder

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  while i<imBreite do begin
  MoveTo(x0 - i,y0 - StrichLaenge);LineTo(x0-i,y0 + StrichLaenge);
  MoveTo(x0 + i,y0 - StrichLaenge);LineTo(x0+i,y0 + StrichLaenge);
  MoveTo(x0 - StrichLaenge,y0 - i);LineTo(x0+StrichLaenge,y0 - i);
  MoveTo(x0 - StrichLaenge,y0 + i);LineTo(x0+StrichLaenge,y0 + i);
  i:= i + Einheit;
end;


Gib also mal bei jeder Schleife in jedem Durchlauf die Variablen aus, die für die Abbruchbedingung verantwortlich sind. hier also:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
ShowMessage(FloatToStr(x));
ShowMessage(FloatToStr(xb));

// und beim anderen:

ShowMessage(FloatToStr(i));
ShowMessage(FloatToStr(Einheit));


Und baue auch abundzu ein Application.ProcessMessages ein, damit du siehst, was gezeichnet wird.