Autor Beitrag
JoachimQ
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 59


D2, D6 und D7
BeitragVerfasst: So 08.01.06 15:32 
Ich möchte mit einem Programm einen Graphen zeichnen.
Folgenden Quellcode habe ich bereits geschrieben.
Leider muss irgendwo ein Fehler sein!
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    ValueListEditor1: TValueListEditor;
    GroupBox2: TGroupBox;
    Image1: TImage;
    GroupBox3: TGroupBox;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var x,y:integer;
    x4,x3,x2,x1,x0:real;
    z,dvx,dvy:real;
    f:boolean;
begin
if Length(ValueListEditor1.Strings[0])>4 THEN
x4:=StrToFloat(Copy(ValueListEditor1.Strings[0],
5,Length(ValueListEditor1.Strings[0])-4)) else x4:=0;
Form1.Caption:=FloatToStr(x4)+'x^4';

if Length(ValueListEditor1.Strings[1])>4 THEN
x3:=StrToFloat(Copy(ValueListEditor1.Strings[1],
5,Length(ValueListEditor1.Strings[1])-4)) else x3:=0;
Form1.Caption:=Form1.Caption+'+'+FloatToStr(x3)+'x^3';

if Length(ValueListEditor1.Strings[2])>4 THEN
x2:=StrToFloat(Copy(ValueListEditor1.Strings[2],
5,Length(ValueListEditor1.Strings[2])-4)) else x2:=0;
Form1.Caption:=Form1.Caption+'+'+FloatToStr(x2)+'x^2';

if Length(ValueListEditor1.Strings[3])>4 THEN
x1:=StrToFloat(Copy(ValueListEditor1.Strings[3],
5,Length(ValueListEditor1.Strings[3])-4)) else x1:=0;
Form1.Caption:=Form1.Caption+'+'+FloatToStr(x1)+'x^1';

if Length(ValueListEditor1.Strings[4])>4 THEN
x0:=StrToFloat(Copy(ValueListEditor1.Strings[4],
5,Length(ValueListEditor1.Strings[4])-4)) else x0:=0;
Form1.Caption:=Form1.Caption+'+'+FloatToStr(x0)+'x^0';

if Length(ValueListEditor1.Strings[5])>4 THEN
dvx:=StrToFloat(Copy(ValueListEditor1.Strings[5],
5,Length(ValueListEditor1.Strings[5])-4)) else dvx:=1;

if Length(ValueListEditor1.Strings[6])>4 THEN
dvy:=StrToFloat(Copy(ValueListEditor1.Strings[6],
5,Length(ValueListEditor1.Strings[6])-4)) else dvy:=1;


f:=false;
{Image1.Canvas.Pen.Color:=$000000;
Image1.Canvas.CleanupInstance;}

Image1.Picture := NIL;
Image1.Canvas.Pen.Color:=$00FF00;
Image1.Canvas.MoveTo(150,0);
Image1.Canvas.LineTo(150,300);
Image1.Canvas.MoveTo(0,150);
Image1.Canvas.LineTo(300,150);
for x:=-150 to 150 do
  begin
  z:=x / dvx;
  y:=trunc((x4*z*z*z*z+x3*z*z*z+x2*z*z+x1*z+x0) / dvy); {or round?}
  if (y>=-150and (y<=150then
    begin
    Image1.Canvas.Pen.Color:=$FF0000;
    if f=false then Image1.Canvas.MoveTo(X+150,Y+150);f:=true;
{    Image1.Canvas.Pixels[X+150,Y+150]:=$FF0000;}
    Image1.Canvas.LineTo(X+150,Y+150);
    end;
  end;
end;

procedure TForm1.Image1Click(Sender: TObject);
var
 Bitmap: TBitmap;
begin
 Bitmap:=Image1.Picture.Bitmap;
 try
   Clipboard.Assign(Bitmap);
 finally
   Bitmap.Free;
 end;
end;

end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconraziel: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am So 08.01.2006 um 15:38
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 08.01.06 15:37 
Wieso, was passiert? Wo hängts?

_________________
Programmers never die, they just GOSUB without RETURN
ebs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 213

Suse Linux 9.2, Win 98, Win NT, Win XP, Win for Workgroups, Win XP SP2, Dos 6.1
D3 Prof, D2005 PE, Delphi 2006 Prof.
BeitragVerfasst: So 08.01.06 21:50 
Du musst doch dein Bitmap erstmal erstellen:
ausblenden Delphi-Quelltext
1:
Bitmap := TBitmap.Create;