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



BeitragVerfasst: So 15.06.03 11:18 
Hey leudz, nen Kumpel von mir hat einen Quelltext geschrieben mit dem ich nich ganz klar komme. Deswegen hab ich hier mal 2 kurze Fragen.

1. Frage: Welche zeichen oder zahlen werden als Double deklariert???

2. Frage: Welche Bedeutung hat das rot markierte im Quelltext, also was macht es????

Mist, das mit dem rot markieren im Queltext geht nicht. Ich schreib das Stück quelltext von dem ich die bedeutung will einfach nochmal mit darunter. Achja vielen dank schon im Voraus!!!!!!!!

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

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn3: TBitBtn;
    procedure FormActivate(Sender: TObject);
    procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type feldtyp = Array [0..3,0..11] of double;

var
  Form1: TForm1;
  tabelle : feldtyp;

implementation

{$R *.DFM}

procedure summe(Var spalte : Integer);
Var j : Integer;
    summe : Double;
begin
  summe := 0;
  for j := 1 to 11 do
    begin
      summe := summe + tabelle[spalte,j];
      form1.stringgrid1.cells[spalte,1] := FloattoStr(summe);
    end;

end;

procedure TForm1.FormActivate(Sender: TObject);
Var zaehler, j, i : Integer;
begin
  with stringgrid1 do
  begin
    for zaehler := 2 to 11 do
      begin
        cells[0,zaehler] := 'Angestellter ' + InttoStr(zaehler);
      end;
    cells[0,1] := 'Summe';
    cells[1,0] := 'Gehalt';
    cells[2,0] := 'Gehalt + Erhöhung';
    cells[3,0] := 'Gehalt + Erhöhung + Weihnachtsgeld';
  end;
  for i := 1 to 3 do
    for j := 1 to 11 do
      begin
        tabelle[i,j] := 0;
        stringgrid1.cells[i,j] := '0';
      end;
end;

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
Var strbuffer : String;
    spalte : Integer;
begin
  with stringgrid1 do
    begin
     if cells[acol,arow] <> '' then
       begin
         Strbuffer := cells[acol,arow];
         tabelle[acol,arow] := Strtofloat(Strbuffer);
         tabelle[acol + 1,arow] := tabelle[acol,arow] + StrtoFloat(edit1.text);
         tabelle[acol + 2,arow] := tabelle[acol + 1,arow] + StrtoFloat(edit2.text);
         cells[acol + 1,arow] := FloattoStr(tabelle[acol + 1,arow]);
         cells[acol + 2,arow] := FloattoStr(tabelle[acol + 2,arow]);
     end;
    end;
  summe(acol);
  spalte := 2;
  summe(spalte);
  spalte := 3;
  summe(spalte);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  case key of
    ',':     key := '.';
    'o','O': key := '0';
  end;
  if not (key in ['0'..'9','.','-',chr(8)]) then key := #0;
end;


procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
Var erhoehung : Double;
    i : Integer;
begin
{   if edit1.text = '' then
     begin
     end
   else
     begin
       erhoehung := StrtoFloat(edit1.text);
       for i := 1 to 11 do
         begin
           if tabelle[1,i] = 0 then
             begin
             end
           else
             begin
               tabelle[2,i] := tabelle[1,i] + erhoehung;
               stringgrid1.cells[2,i] := FloattoStr(tabelle[2,i]);
             end;
          end;
     end;  }

end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
Var erhoehung : Double;
    i : Integer;
begin
  { if edit2.text = '' then
     begin
     end
   else
     begin
       erhoehung := StrtoFloat(edit2.text);
       for i := 1 to 11 do
         begin
           if tabelle[2,i] = 0 then
             begin
             end
           else
             begin
               tabelle[3,i] := tabelle[2,i] + erhoehung;
               stringgrid1.cells[3,i] := FloattoStr(tabelle[3,i]);
             end;
         end;
     end; }

end;
procedure TForm1.Edit1Exit(Sender: TObject);
Var erhoehung : Double;
    i, spalte : Integer;
begin
   spalte := 2;
   if edit1.text = '' then
     begin
     end
   else
     begin
       erhoehung := StrtoFloat(edit1.text);
       for i := 1 to 11 do
         begin
           if tabelle[1,i] = 0 then
             begin
             end
           else
             begin
               tabelle[2,i] := tabelle[1,i] + erhoehung;
               tabelle[3,i] := tabelle[2,i] + StrtoFloat(edit2.text);
               stringgrid1.cells[2,i] := FloattoStr(tabelle[2,i]);
               stringgrid1.cells[3,i] := FloattoStr(tabelle[3,i]);
             end;
          end;
     end;
  summe(spalte);
  spalte := 3;
  summe(spalte);
end;

procedure TForm1.Edit2Exit(Sender: TObject);
Var erhoehung : Double;
    i, spalte : Integer;
begin
   spalte := 3;
   if edit2.text = '' then
     begin
     end
   else
     begin
       erhoehung := StrtoFloat(edit2.text);
       for i := 1 to 11 do
         begin
           if tabelle[2,i] = 0 then
             begin
             end
           else
             begin
               tabelle[3,i] := tabelle[2,i] + erhoehung;
               stringgrid1.cells[3,i] := FloattoStr(tabelle[3,i]);
             end;
         end;
     end;
   summe(spalte);
end;


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:
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
Var strbuffer : String;
    spalte : Integer;
begin
  with stringgrid1 do
    begin
     if cells[acol,arow] <> '' then
       begin
         Strbuffer := cells[acol,arow];
         tabelle[acol,arow] := Strtofloat(Strbuffer);
         tabelle[acol + 1,arow] := tabelle[acol,arow] + StrtoFloat(edit1.text);
         tabelle[acol + 2,arow] := tabelle[acol + 1,arow] + StrtoFloat(edit2.text);
         cells[acol + 1,arow] := FloattoStr(tabelle[acol + 1,arow]);
         cells[acol + 2,arow] := FloattoStr(tabelle[acol + 2,arow]);
     end;
    end;
  summe(acol);
  spalte := 2;
  summe(spalte);
  spalte := 3;
  summe(spalte);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  case key of
    ',':     key := '.';
    'o','O': key := '0';
  end;
  if not (key in ['0'..'9','.','-',chr(8)]) then key := #0;
end;
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: So 15.06.03 14:34 
Auf den ersten Blick (ohne den ganzen oberen Code mit einzubeziehen), wird geprüft, ob eine bestimmte Zeile/Spalte gefüllt ist und wenn dem so ist, werden weitere Zellen gefüllt und Berechnungen durchgeführt.

Das OnKeyPress prüft:

Wenn "," gedrückt wird, wird's als "." geschrieben.
Wenn ein "o" oder "O", dann wird das eine "0".
Wenn die gedrückte Taste nicht zwischen "0" und "9" oder "." oder "-" oder Chr(8) -> Keine Ahnung, welche Taste das ist, dann wird ein Rückschritt gemacht, sprich Backspace gedrückt..

Das nur mal als kurze Info. Weiteres kann ich dir im Moment nicht sagen, bin knapp an Zeit..

_________________
Hasta La Victoria Siempre
baddy Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Do 19.06.03 13:40 
Ok nun hab ich's kapiert leute. sorry aber kannte mich mit den Board rules hier net so aus. Also@terra das mit dem keypress ist jetzt klar, aber was bedeuten acol und arow??? Das hab ich immer noch net verstanden.


greetz baddy
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Do 19.06.03 13:43 
Hmm, soweit ich die Delphi Hilfe verstehe wird SetEditText dann aufgerufen wenn (eins von beiden)

1. Die Zelle bearbeitet wird (???)
2. Die Zelle geschrieben wird (???)

ARow und ACol sind halt die Reihe und Spalte die bearbeitet werden.

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
baddy Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Do 19.06.03 14:32 
Ach und acol und arow werden automatisch erkannt, also welche spalte und zeile gerade beschrieben wird????
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Do 19.06.03 14:56 
Ja (soweit ich das seh)

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
baddy Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Do 19.06.03 18:58 
Gut das hilft mir schon mal weiter danke. Hab dann mal noch ne letzte Frage. Und zwar kommt folgendes im Prog öfters mal vor:


tabelle[...]:=...;
stringrid1.cells[...]:=...;

Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.FormActivate(Sender: TObject); 
Var zaehler, j, i : Integer; 
begin 
  with stringgrid1 do 
  begin 
    for zaehler := 2 to 11 do 
      begin 
        cells[0,zaehler] := 'Angestellter ' + InttoStr(zaehler); 
      end; 
    cells[0,1] := 'Summe'; 
    cells[1,0] := 'Gehalt'; 
    cells[2,0] := 'Gehalt + Erhöhung'; 
    cells[3,0] := 'Gehalt + Erhöhung + Weihnachtsgeld'; 
  end; 
  for i := 1 to 3 do 
    for j := 1 to 11 do 
      begin 
        tabelle[i,j] := 0; 
        stringgrid1.cells[i,j] := '0'; 
      end; 
end;


Welchen Nutzen hat es jetzt, dass nochmal stringgrid1.cells hingeschrieben wird. Mit der tabelle ist doch eigentlich schon erfasst, oder seh ich das falsch????
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Do 19.06.03 19:12 
das hast du richtig gesehen, aber tabelle wird nicht automatisch im stringgrid angezeigt, deshalb musst du die null auch nochmal in das Stringgrid schreiben...

Gruß
Ken