Autor Beitrag
flex-17
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Fr 22.06.07 16:41 
Wir müssen in Informatik einen kleinen Rechner programmieren. Dieser funktioniert bei mir auch, allerdings will sich die StringGrid Tabelle nicht speichern lassen -.- . Wenn ich auf den SpeicherButton klicke passiert nix -.- ...

...weiß jemand Rat?

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

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    FLabel: TLabel;
    EStartwert: TEdit;
    BBerechnen: TButton;
    LAnfang: TLabel;
    LEnde: TLabel;
    EEndwert: TEdit;
    BSchliessen: TButton;
    Label1: TLabel;
    BSpeichern: TButton;
    SaveDialog1: TSaveDialog;
    BDrucken: TButton;


    procedure FormCreate(Sender: TObject);
    procedure BBerechnenClick(Sender: TObject);
    procedure BSpeichernClick(Sender: TObject);
    procedure BSchliessenClick(Sender: TObject);



  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1; i, Startwert, Endewert, Quadrat, x, y: integer;
  Wurzel: Real;
  sinus: Real;
  hoch: Real;
  cosinus: Real;
  hochvier: Real;
  Datei: Textfile;
  Dateiname: string;
  f: textfile;



implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin

{7 Spalten - 'Name der Spalte'}

 StringGrid1.Cells[0,0] := 'Wert';
 StringGrid1.Cells[1,0] := 'Wurzel';
 StringGrid1.Cells[2,0] := 'Sinus' ;
 StringGrid1.Cells[3,0] := 'Kosinus';

 StringGrid1.Cells[4,0] := 'x^2';
 StringGrid1.Cells[5,0] := 'x^3';
 StringGrid1.Cells[6,0] := 'x^4';






end;

procedure TForm1.BBerechnenClick(Sender: TObject);
begin
Try
 Startwert := StrToInt(EStartwert.Text);
 Endewert := StrToInt(EEndwert.Text);

 except
 showmessage  ('Bitte tippen sie nur ganze Zahlen ein');
 end;
 with StringGrid1 do
        for i:= 1 to endewert-startwert+1 do begin
        y:=i+startwert  -1;
        cells[0,i]:= inttostr(y);
         end;

   stringgrid1.Rowcount:=endewert+2-startwert;
   for i:= 1 to Endewert-startwert+1 do
   with StringGrid1 do
   Begin
   x:=(i-1)+startwert;


   { Rechenanweisungen}

Wurzel :=  sqrt(x);
Cells[1,i] := FloatToStrF(Wurzel, ffFixed, 10,3);

Sinus := sin(x*Pi/180);
Cells[2,i] := FloatToStrF(Sinus, ffFixed, 10,3);

Cosinus := cos(x*Pi/180);
Cells[3,i] := FloatToStrF(Cosinus, ffFixed, 10,3);

   Quadrat := x * x;
Cells[4,i] := FloatToStrF(Quadrat, ffFixed, 10,3);

   hoch:= x * x * x;
   Cells[5,i] := FloatToStrF(hoch, ffFixed, 10,3);

   hoch:= x * x * x * x;
   Cells[6,i] := FloatToStrF(hoch, ffFixed, 10,3);

end;
end;

procedure TForm1.BSchliessenClick(Sender: TObject);
begin
Form1.Close;
end;


procedure SaveStringGridToFile(StringGrid: TStringGrid; const FileName: String);
var
  F: TStringList;
  i: Integer;
begin
  F := TStringList.Create;
  try
    F.Add(IntToStr(StringGrid.RowCount));
    F.Add(IntToStr(StringGrid.ColCount));
    for i := 0 to (StringGrid.RowCount - 1) do
      F.Add(StringGrid.Rows[i].CommaText);
    F.SaveToFile(FileName);
  finally
    F.Free;
  end;
end;

procedure TForm1.BSpeichernClick(Sender: TObject);
begin
  SaveStringGridToFile(StringGrid1, 'lol.txt');
end;




end.


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 22.06.07 21:29 
Hallo,

passiert wirklich nichts, oder wird die Datei nicht dort gespeichert wo Du sie anschließend suchst?

Setz doch mal einen Haltepunkt in die procedure BSpeichernClick.
Stopt Delphi mit der Ausführung nicht an der Stelle, hast Du vermutlich das Ereignis im OI nicht rictig zugewiesen.

Denke aber eher das es ein Problem der nicht vollständigen Pfadangabe ist.
ausblenden Delphi-Quelltext
1:
SaveStringGridToFile(StringGrid1,    'lol.txt');					

Hier mal ein paar Stichworte dazu:
Anwendungsverzeichnis <> Arbeitsverzeichnis
ExtractFilePath
ParamStr

//Edit:
Fast vergessen, :welcome: in der EE

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )