Autor Beitrag
orangata
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Di 04.05.10 15:51 
Hallo,

ich bin absoluter Neuling.
Nach einigen kleineren Programmen, die alle relativ problemlos liefen, gilt es jetzt folgende Aufgabe zu lösen:
Eine Zufallszahl zw 1 und 100 soll erraten werden.
Im Quelltext wird bei Eingabe Edit wird mir ein Fehler angezeigt, warum und wie kann er behoben werden:

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

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Eingabeedit: TEdit;
    ErgebnisPanel: TPanel;
    NeuButton: TBitBtn;
    RatenButton: TBitBtn;
    AbbruchButton: TBitBtn;
    procedure AbbruchButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RatenButtonClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
  var Zufallszahl : integer;
procedure TForm1.AbbruchButtonClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
  Zufallszahl:=Random(100)+1 ;
end;

procedure TForm1.RatenButtonClick(Sender: TObject);
var Eingabe: Integer;
begin
  Eingabe:=StrToInt(EingabeEdit.Text);
  if Eingabe = Zufallszahl
    then ErgebnisPanel.Caption:=' Das war richtig!! '
    else if Eingabe<Zufallszahl
    then ErgebnisPanel.Caption:='Die Zahl ist zu klein!'
    else ErgebnisPanel.Caption:='Die Zahl ist zu groß!' ;
  EingabeEdit.SetFocus;
end;

end.

Die Unit ist eingebunden in das Project1 eingebunden

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {EingabeEdit};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TEingabeEdit , EingabeEdit);
  Application.Run;
end.


Vielen Dank für eure Hilfe

Gruß
orangata

Moderiert von user profile iconGausi: B- durch Delphi-Tags ersetzt
Webo
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 577
Erhaltene Danke: 14

Win 7, Debian
C# (Visual Studio 2013), PHP, C, C++ (Eclipse, KDevelop)
BeitragVerfasst: Di 04.05.10 16:28 
An welcher Stelle genau wird denn der Fehler angezeigt ? Und noch wichtiger: was für ein Fehler ?

_________________
Man kann nur das aus dem Ärmel schütteln, was man auch vorher reingesteckt hat.
orangata Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Di 04.05.10 18:16 
Zeile 8 Quelltext, EingabeEdtit

Gruß
orangata
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Di 04.05.10 18:19 
In beiden oben geposteten Quelltexten ist die Zeile 8 leer :roll:

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
orangata Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Di 04.05.10 18:21 
Sorry,
11: Application.CreateForm(TEingabeEdit , EingabeEdit);
Application.Run;
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Di 04.05.10 18:24 
Das bringt garnichts...das sagt aus "Es ist ein Fehler im Programm"

Das einzige was mir überhaupt an deinem Code komisch vorkommt ist, dass du Zufallszahl irgendwie an einer komischen Stelle definierst...

Edit:
Mach mal Breakpoints. Und: Wie lautet der Fehler? Access Violation?

Edit2:

Alles Quatsch. Was machst du denn da mit dem EingabeEdit? In dem zweiten Quelltext solltest du eigentlich erstmal nicht rumfummeln ^^ Da wo EingabeEdit steht muss Form1 würd ich sagen

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: Di 04.05.10 18:31 
Da passt etwas nicht zusammen:
ausblenden Delphi-Quelltext
1:
2:
3:
program Project1;
[...]
  Application.CreateForm(TEingabeEdit EingabeEdit);


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
unit Unit1;
[...]
type
  TForm1 class(TForm)
[...]
var
  Form1: TForm1;
Webo
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 577
Erhaltene Danke: 14

Win 7, Debian
C# (Visual Studio 2013), PHP, C, C++ (Eclipse, KDevelop)
BeitragVerfasst: Di 04.05.10 18:43 
ausblenden Delphi-Quelltext
1:
Application.CreateForm(TEingabeEdit , EingabeEdit);					
versucht eine Form zu erzeugen. EingabeEdit ist aber ein Edit was mit TForm herzlich wenig zu tun hat ;-) Also einfach durch TForm1, Form1 ersetzen und es müsste passen.

_________________
Man kann nur das aus dem Ärmel schütteln, was man auch vorher reingesteckt hat.
orangata Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Di 04.05.10 18:44 
danke ;-), es funzt