Autor Beitrag
ConditionZero
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 13.09.06 21:20 
hi

kann mir vielleicht jmd. weiterhelfen, also ist recht dringend muss des teil donnerstag abend abgeben. Ich will leere Zeilen aus einem StringGrid löschen, aber erst wenn das Formular sichtbar wird. Eig. wollte ich es erst einfach eine abfrage mit if machen aber die Anzahl der beschriebenen Zellen variiert immer. Hab aber keine Ahnung wie das gehen soll habs jetzt mal so ausprobiert des geht aber nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TPopUp.FormShow(Sender: TObject);
var
i,x,y:Integer;
begin
x:=1;
y:=MSGPlaner.TabelleGrid.RowCount;
i:=1;
while x<=y do
  begin
  i:=i+1;
  x:=x+1;
  while TabelleGrid1.Rows[i].Text = (''do
    begin
    TabelleGrid1.Rows[i].Delete(i);
    end;
  end;
end;



Danke im vorraus schonmal.
Lg Marc

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 13.09.06 22:22 
Ich würde die Schleife vom Ende zum Anfang machen und die Inhalte vor dem Vergleich noch Trimmen.

_________________
Markus Kinzler.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 13.09.06 22:43 
ok, danke aber was heißt trimmen? :D weil ich versteh darunter "klein machen"
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 13.09.06 22:45 
Der Befehl Trim() entfernt Leerzeichen am Anfang und Ende eines Strings so daß aus ' ' oder ' ' '' wird.

_________________
Markus Kinzler.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 13.09.06 23:08 
achso ok. also jz kommt aba ein fehler wenn ich auf den Button drück: "Im Projekt Projekt1.exe ist eine Exception der Klasse EInvalidGridOperation aufgetreten. Meldung: 'Es können keine Zeilen des Tabellengitters gelöscht oder eingefügt werden'. also des ist wenn so mach:

ausblenden Delphi-Quelltext
1:
while Trim(TabelleGrid1.Rows[i].Text) = Trim(''do					


un wenn ich so mach passiert alles wie davor:

ausblenden Delphi-Quelltext
1:
while TabelleGrid1.Rows[i].Text = Trim(''do					
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 13.09.06 23:15 
Wie gesagt von hinten, sonst gibts Probleme wenn du etwas löschst. Du kannst ja auch ne For-downto-Schleife nehmen.

_________________
Markus Kinzler.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 13.09.06 23:31 
hä? wie von hinten sorry ich steh grad voll aufm schlauch >.<
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mi 13.09.06 23:51 
ausblenden Delphi-Quelltext
1:
2:
3:
for i:=TabelleGrid1.Rows.Count-1 downto 0 do
  if Trim(TabelleGrid1.Rows[i].Text)='' then
    TabelleGrid1.Rows.Delete(i);

Ungetestet, aber das Prinzip dürfte stimmen.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Do 14.09.06 00:05 
hm funktioniert leider nicht, kommt immer noch der gleiche fehler :-(
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 14.09.06 00:07 
user profile iconConditionZero hat folgendes geschrieben:
'Es können keine Zeilen des Tabellengitters gelöscht oder eingefügt werden'

Hmm.. warum gibts überhaupt die Methode Delete, wenn man sie nicht aufrufen darf? :shock:
Musst wohl drumrum denken und einen Trick anwenden: Statt dem Löschen, überträgst du die nicht leeren Zeilen in eine NEUE Liste und löschst die alte komplett. Dann schreibst du die Werte der Neuen in die Alte.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 14.09.06 00:19 
So sollte es das tun:
ausblenden 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:
procedure DeleteRow(aGrid : TStringGrid; index : Integer);
var
  i_row, i_col : Integer;
begin
  for i_row := index to aGrid.RowCount - 2 do
    for i_col := 0 to aGrid.ColCount - 1 do
      aGrid.Cells[i_col, i_row] := aGrid.Cells[i_col, i_row+1];

  aGrid.RowCount := aGrid.RowCount-1;
end;

function IsEmptyRow(aGrid : TStringGrid; index : Integer) : Boolean;
begin
  result := Trim(aGrid.Rows[index].Text) = '';
end;

procedure DeleteEmptyRows(aGrid : TStringGrid);
var
  i: Integer;
begin
  for i := aGrid.RowCount-1 downto 0 do
    if IsEmptyRow(aGrid, i) then
      DeleteRow(aGrid, i);
end;


Aufruf sollte klar sein, mit "DeleteEmptyRows(DeinStringGrid)"

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Do 14.09.06 00:25 
will auch nicht auf die weiße klappen kommt mal keine fehlermeldung, aber die leeren zeilen sind immer noch da


Edit: ok sry hab grad en fehler von meiner seite gemacht, funktioniert alles bestens dankeschön jetzt kann ich ja beruhigt schlafen gehn un des teil morgen schön cool meiner lehrerin geben :D
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 14.09.06 00:32 
Ich hab den Quellcode bei mir probiert, funktioniert bei mir prima :gruebel:

Ich habe auch gerade nochmal ein leeres Projekt erstellt, StringGrid drauf gepackt, Source von hier reinkopiert :arrow: funktioniert. Lediglich in der Optionen des StringGrid noch "goEdition" auf true, damit ich da was eintragen kann.

Vielleicht ersetz mal "IsEmptyRow" durch das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function IsEmptyRow(aGrid : TStringGrid; index : Integer) : Boolean;
var
  i_col : Integer;
begin
  for i_col := 0 to aGrid.ColCount - 1 do
    if Trim(aGrid.Cells[i_col, index]) <> '' then
    begin
      result := False;
      exit;
    end;

  result := true;
end;


Das ist zwar nicht schön, sollte aber gehen :zwinker:


//edit: Na, dann bin ich ja froh :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".