Autor Beitrag
SkyX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win Xp
Delphi 2007 Prof
BeitragVerfasst: Mi 27.02.08 20:21 
Guten abend,
ich habe folgendes Problem, ich möchte wenn man auf den Button 1 klickt das er sozusagen das einmal eins ausgibt! in den Anzeigen auserhalb des Stringgrid tut er mir die Zahlen normal ausgeben 1-10 bzw soll er das einmal eins von 11-20 können deswegen sind die werte etwas anders! Jedoch gibt er in den Weißen Felder nix aus, bleibt alles leer!
Als fehler wird die var y angezeigt das diese nach dem durchlaufen undefiniert sei...
Brauche unbedingt hilfe danke!
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x,y : integer;

implementation

{$R *.dfm}

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

procedure TForm1.Button1Click(Sender: TObject);
VAR x,y,produkt :INTEGER;
//Beschriftung der Stringrids
begin

 FOR x:= 1 TO 10 DO
  BEGIN
   Form1.StringGrid1.Cells [x,0]:= InttoStr(x+10);
    END;
     
  FOR y:= 1 TO 10 DO
   BEGIN
    Form1.StringGrid1.Cells [0,y]:= InTToStr(y+10)
    END;

//Verarbeitung und Ausgabe
FOR x:= 1 TO 10 DO
 BEGIN
   FOR y:= 1 to 10 DO
   produkt:= (x+10)*(y+10)  ;
   Form1.StringGrid1.Cells [x,y]:= inttoStr(produkt);
   END;
    END;

procedure TForm1.Button2Click(Sender: TObject);
begin
StringGrid1.Rows[y].Clear();
StringGrid1.Cols[x].Clear();
end;

end.


Moderiert von user profile iconNarses: Quote- durch Delphi-Tags ersetzt
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 27.02.08 20:28 
Hi! Bitte verwende die Delphi-Tags. [delphi] Code [/delphi]
Zu Deinem Problem: Ich denke bei Deiner Ausgabe fehlt ein begin bei der zweiten For-Schleife.

Grüße
Marc
SkyX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win Xp
Delphi 2007 Prof
BeitragVerfasst: Mi 27.02.08 20:33 
Das bringt nix wenn ich ein Begin rein setzte, bleibt einfach leer!
Fehler:
ausblenden Delphi-Quelltext
1:
[Warnung] Unit1.pas(59): FOR-Schleifenvariable 'y' kann nach Durchlauf undefiniert sein					
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 27.02.08 20:47 
Ich habe Deinen Quelltext nun einmal schnell kopiert und ausgeführt. Mit dem eingefügten Begin funktionierts auch! ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for x:= 1 TO 10 do begin
    for y:= 1 TO 10 do begin
        produkt:= (x+10)*(y+10) ;
        Form1.StringGrid1.Cells [x,y]:= inttoStr(produkt);
    end;
end;
SkyX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win Xp
Delphi 2007 Prof
BeitragVerfasst: Mi 27.02.08 20:52 
Juhu Danke hat geklappt!!!!
Ähm meine andere frage wie kann ich eine Procedure schreiben?
Habe mir das vom Unterricht leider nicht gemerkt...
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 27.02.08 20:55 
Das freut mich. :)
Zum Thema Prozeduren und Co. solltest Du bei user profile iconChristian S. Crashkurs etwas finden.

Du kannst dir übrigens bei Schleifen und If-Strukturen das Begin und End sparen, wenn es sich nur auf die nächste Zeile bzw. Befehl bezieht.
Also z.B. for x:= 1 to 10 do StringGrid1.Cells [x,0] := IntToStr(x+10);
Erhöht in diesem Fall IHMO die Übersicht.

Grüße
Marc.