Autor Beitrag
mara_buh
Hält's aus hier
Beiträge: 8


Delphi 6
BeitragVerfasst: Sa 22.04.06 08:21 
Ich hab hier ein kleines Programm geschrieben, aber ich soll noch irgendwie eine oder meherere Funktionen einbauen. Die müssen wir vorher deklarieren, aber wie mach ich das ??

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

interface

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

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Label1: TLabel;
    ComboBox2: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label10: TLabel;
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

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

procedure TForm1.Button2Click(Sender: TObject);
begin
 edit1.clear  ;
 edit2.clear ;
 edit3.clear ;
 edit4.clear ;
end;

procedure TForm1.Button1Click(Sender: TObject);
var tarif, preis: extended;
var i, km : Integer     ;
var datum1, datum2, uhrzeit1, uhrzeit2 : string ;
begin datum1:=(edit1.text);
      datum2:=(edit3.text);
      uhrzeit1:=(edit2.text);
      uhrzeit2:=(edit4.text);
case combobox1.itemindex of
   0: tarif:=0.2 ;
   1: tarif:=0.5 ;
   2: tarif:=0.25 ;
end;
case combobox2.itemindex of
   0: km:=25 ;
   1: km:=50 ;
   2: km:=75 ;
   3: km:=100 ;
   4: km:=200 ;
   5: km:=500 ;
   6: km:=1000 ;
end;
i:=1   ;
repeat
    preis:=i*tarif ;
    i:=i+1 ;
until i=km+1 ;
if  radiobutton1.Checked then preis:=preis*2 ;
if  checkbox1.Checked then preis:=Preis+10 ;
showmessage('Ihre Reisedaten: Hinfahrt: am ' + (datum1) + ' um ' + (uhrzeit1) +
' Rückreise: am '  + (datum2) + ' um ' + (uhrzeit2) + ' Preis: ' 
+ Floattostr(preis)+ ' € ');

end;

end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt


Zuletzt bearbeitet von mara_buh am Mo 24.04.06 15:32, insgesamt 1-mal bearbeitet
Jetstream
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 222



BeitragVerfasst: Sa 22.04.06 09:00 
1. du musst pro prozedur nur einmal "var" schreiben.
2. statt deiner 5-zeilen repeat-schleife tuts auch ne 1-zeilen for-schleife:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
i:=1   ;
repeat
    preis:=i*tarif ;
    i:=i+1 ;
until i=km+1 ;

// wird zu

for i:=1 to km do preis := i * tarif;

// geht übrigens noch schneller mit

preis := km * tarif


3. dir sind also die ideen ausgegangen ?
hmmm, da das programm weder besonders umfangreich noch kompliziert ist, kann man so ziemlich alles einbauen.

wie wärs mit nem promille-berechner oder ner graphischen ausgabe ?
ein weg-zeit-diagramm oder so =)