Autor Beitrag
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Di 19.07.05 10:03 
Hallo Leute,

Ich habe ein Grid in dem mehere Einträge angelegt werden. Wenn diese Einträge dann gespeichert werden wird vorher einiges überprüft darunter auch ob sich leere Zeilen in diesem Grid befinden wenn ja dann werden diese gelöscht.

Ich habe bereits eine kleine Funktion vor längerer Zeit geschrieben doch der Fehler im Code ist offensichtlich.. Es wird nur eine einzige Zeile gelöscht und danach nichts mehr da ja lCounter und/oder lRowCount bereits über der Anzahl der Zeilen sind.

Kann mir jemand sagen wie ich dann die Variablen bzw. die Schleife anpassen muss danmit er wirklich alle leeren Zeile herauslöscht? Hab grad die totale Denkblokade.. -.-

Hier mein Code:

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:
25:
26:
27:
28:
29:
...
var
  lCounter: integer;
  lRowCount: integer;
begin
  result := false;
  lCounter := 0;
  lRowCount := dxProjectGrid.RowCount;
  try
    for lCounter := 0 to lRowCount - 1 do begin
      if Assigned(dxProjectGrid.Items[lCounter]) then begin
        if (dxProjectGrid.Items[lCounter].Values[0] = ''and
           (dxProjectGrid.Items[lCounter].Values[1] = ''then begin
           dxProjectGrid.Items[lCounter].Destroy;
        end;
      end;
    end;
    result := true;
    lCounter := 0;
  except
    on E:Exception do begin
      aErrorStr := 'Fehler beim entfernen der leeren Zeilen aus dem '
                 + 'Grid zur Tätigkeitszuordnung' + #10#10
                 + 'Fehlerhafte Zeile: ' + IntToStr(lCounter + 1) + #10#13
                 + 'Windows-Fehlermeldung: ' + E.Message;
    end;
  end;
end;
..


Danke!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 19.07.05 10:44 
Mach es mit einem Downto.
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Di 19.07.05 10:47 
Hi,

vielleicht geht's ja irgendwie so : (nich getestet, weiß auch nich was fürn Grid du da nimmst)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
For lcounter := dxProjectGrid.RowCount -1 Downto 0 do begin;
  if (dxProjectGrid.Items[lCounter].Values[0] = ''and
     (dxProjectGrid.Items[lCounter].Values[1] = ''then begin
   dxProjectGrid.Rows[lCounter] := dxProjectGrid.Rows[dxProjectGrid.RowCount -1];
   //dxProjectGrid.Items[dxProjectGrid.RowCount-1].free
   dxProjectGrid.RowCount := sxProjectGrid.RowCount -1;
  end;
 end;


Da das leere Objekt mit dem letzten getauscht wird geht allerdings eine eventuelle Sortierung flöten...naja wahrscheinlich gibs da auch noch irgendwo nen Haken...
viel Spaß beim rumtüfteln... :)

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Alpha_Wolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Di 19.07.05 10:56 
Hm.. downto ;) mann mann mann.. ich denk irgendwie manchmal zu kompliziert :lol:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
...
    for lCounter := dxProjectGrid.RowCount downto 0 do begin
      if Assigned(dxProjectGrid.Items[lCounter]) then begin
        if (dxProjectGrid.Items[lCounter].Values[0] = ''and
           (dxProjectGrid.Items[lCounter].Values[1] = ''then begin
           dxProjectGrid.Items[lCounter].Destroy;
        end;
      end;
...


@Arno Nym

Ich verwende die ExpressQuantumTreeList 3.2.2 die man allerdings auch als Grid verwenden kann. Grund dafür war das ich einen Footer brauchte und noch einige Dinge mehr.

Infos zur Komponente: [url]www.devexpress.com[/url]

Dankeschön für die Hilfe :)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 19.07.05 10:59 
Bitte korrigieren:
ausblenden Delphi-Quelltext
1:
 for lCounter := dxProjectGrid.RowCount-1 downto 0 do begin					

Da fehlt bei dir das "-1".
Alpha_Wolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Di 19.07.05 11:08 
Du hast recht 100%ig richtig ist es mit "-1". Werds auch so machen.

Ohne funktioniert es in diesem Fall auch..

EDIT:

ok funktioniert einwandfrei.. =) Danke nochmals