Autor Beitrag
MeistaBene
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 18.09.06 16:45 
moin,
habe folgendes kleines problem. versuche verzweifelt den inhalt eines stringgrid in einen array reinzubekommen, aber ich bekomme immer einen Fehler.
hier ist mein prox. lassen die felder erst ausfüllen, da ich das als fehlerquelle ausschließen wollte.
der user des prox soll erst die anzahl von messwerten auswählen und sie dann selber eingeben können. dies ist nur ein test warum es mit dem stringgrid und dem array nicht klappt.

mfg meistabene

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

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Button1: TButton;
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  daten : array of array of string;


implementation

{$R *.dfm}

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
    0: stringgrid1.ColCount := 1;
    1: stringgrid1.ColCount := 7;
    2: stringgrid1.ColCount := 9;
    3: stringgrid1.ColCount := 11;
    4: stringgrid1.ColCount := 13;
    5: stringgrid1.ColCount := 15;
    6: stringgrid1.ColCount := 17;
    7: stringgrid1.ColCount := 19;
    8: stringgrid1.ColCount := 21;

  end;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
begin
case ComboBox2.ItemIndex of
    0: stringgrid1.rowCount := 1;
    1: stringgrid1.rowCount := 2;
    2: stringgrid1.rowCount := 3;
    3: stringgrid1.rowCount := 4;
    4: stringgrid1.rowCount := 5;
    5: stringgrid1.rowCount := 6;
    6: stringgrid1.rowCount := 7;
    7: stringgrid1.rowCount := 8;
    8: stringgrid1.rowCount := 9;
    9: stringgrid1.rowCount := 10;
    10:stringgrid1.rowCount := 11;

  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i, j : integer;
begin
  for i := 0 to (stringgrid1.RowCount-1) do
   for j := 0 to (stringgrid1.ColCount-1) do
    begin
    stringgrid1.Cells[j,i] := inttostr(j)+inttostr(i);
    end;


 SetLength(daten,(stringgrid1.rowcount),(stringgrid1.ColCount));
  for i := 0 to (stringgrid1.RowCount) do
   for j := 0 to(stringgrid1.ColCount) do
    begin
    daten[j,i] := stringgrid1.Cells[j,i];
    end;

end;

end.


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


Zuletzt bearbeitet von MeistaBene am Mo 18.09.06 21:43, insgesamt 2-mal bearbeitet
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mo 18.09.06 16:49 
Du verwendest ein dynamisches Array, soll heißen, bevor du Werte in dein Array speichern kannst, musst du den Speicher erst mit Setlength(Array, Länge); reservieren ;)
MeistaBene Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 18.09.06 17:03 
SetLength(daten,(stringgrid1.rowcount),(stringgrid1.ColCount));


so in etwa kann das aussehen oder?? Das habe ich auch gemacht und da die länge von dem benutzer bestimmt werden kann habe ich die anzahl der spalten und zeilen eingebunden

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
kotzekocher
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 19.09.06 12:40 
Ich glaube, du hast bei der Zuweisung
ausblenden Delphi-Quelltext
1:
daten[j,i] := stringgrid1.Cells[j,i];					

die Dimensionen vertauscht. Richtig muss es heißen
ausblenden Delphi-Quelltext
1:
daten[i,j] := stringgrid1.Cells[i,j];					

Es dürfte nur gehen, solange Zeilen und Spaltenanzahl gleich sind. Was kommt denn für ein Fehler?
MeistaBene Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Di 19.09.06 13:51 
Es ist ein EAccessViolation, zugriffsverletzung bei adresse ####### in modul project1. lesen bei adresse ########.

umgedreht habe ich auch schon und es hilft nicht. bin am verzweifeln
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: Di 19.09.06 15:35 
Hallo,

einmal nimmst Du Count - 1, dann wieder nur Count :!: , vermute daher die Zugriffsverletzung.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);  
var i, j : integer;  
begin  
  for i := 0 to (stringgrid1.RowCount-1) do  
   for j := 0 to (stringgrid1.ColCount-1) do  
    begin  
    stringgrid1.Cells[j,i] := inttostr(j)+inttostr(i);  
    end;  

 SetLength(daten,(stringgrid1.rowcount),(stringgrid1.ColCount));  
  for i := 0 to (stringgrid1.RowCount) do  
   for j := 0 to(stringgrid1.ColCount) do  
    begin  
    daten[j,i] := stringgrid1.Cells[j,i];  
    end;   
end;

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