Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Stringrid Zeilen hinzufügen und löschen (https://www.delphipraxis.net/84860-stringrid-zeilen-hinzufuegen-und-loeschen.html)

schuetzejanett 22. Jan 2007 22:04


Stringrid Zeilen hinzufügen und löschen
 
Hallo,

erstelle dynamisch Stringgrids welche in einem array gespeichert sind.
Nun möchte ich während der anweisung beliebig zeilen hinzufügen oder auch wieder löschen
Aber wenn ich mit rowcount die zeilenanzahl auslese und erhöhe oder senke bekomme ich eine exception( Zugriffsverletzung bei Adresse...)Woran könnte das liegen und gibt es eine elegantere lösung dies zu tun?

Antigo 22. Jan 2007 22:15

Re: Stringrid Zeilen hinzufügen und löschen
 
Hast du die Objekte auch instanziert/erstellt?

Also meineStringrids[i]:=TStringrid.create;

schuetzejanett 22. Jan 2007 22:20

Re: Stringrid Zeilen hinzufügen und löschen
 
ja ich sehe sie ja auch erhalte nur erhalte nur manchmal eine exception beim hinzufügen oder löschen

hier mal der ausschnitt des codes wo ich die stringgrids initialisiere , erstelle

Delphi-Quellcode:
private
    astringgrid: array of TStringgrid;

...

setlength(astringgrid,playerList.Count);

for j := Low(TabTitles) to High(TabTitles) do
              begin
                atabsheet[j] := TTabSheet.Create(aPageControl[i]) ;
                with atabsheet[j] do
                  begin
                    PageControl := aPageControl[i];
                    Name := 'ts' + TabTitles[j];
                    Caption := TabTitles[j];
                    astringgrid[(i*2+j)] := TStringgrid.Create(atabsheet[j]);
                    with astringgrid[(i*2+j)] do
                      begin
                        parent := atabsheet[j];
                        top:=5;
                        width := 140;
                        defaultrowheight := 15;
                        scrollbars := ssvertical;
                        if j = 0 then
                          begin
                            rowcount := 2;
                            colcount := 4;
                            fixedrows := 1;
                            defaultcolwidth := 40;
                            colwidths[0] := 20 ;
                            cells[1,0]:= '1';
                            cells[2,0]:= '2';
                            cells[3,0]:= '3';
                          end
                        else
                          begin
                            colcount := 2;
                            fixedCols := 0;
                            defaultcolwidth := 60;
                            cells[0,0]:= 'Feld';
                            cells[1,0]:= 'Treffer';
                            afields := playerList.Player[i].fields;
                            rowcount := length(afields);
                            for k := 0 to high(afields) do
                              begin
                                cells[0,k+1] := inttostr(afields[k].field);
                                Cells[1,k+1] := inttostr(afields[k].anz);
                              end;//for
                          end;//else
                      end;//with stringgrid(2i+1)
                  end;//atabsheet[j]
               end;//for tabtitles
und jetzt wo ich eine zeile hinzufüge

Delphi-Quellcode:
 row := (astringgrid[currentplayerID *2].rowcount);
  astringgrid[currentplayerID *2].rowcount := (row +1);
  astringgrid[currentplayerID *2].Cells[0,row-1] := inttostr(row-1);
  astringgrid[currentplayerID *2].Cells[1,row-1] := points[0];
  astringgrid[currentplayerID *2].Cells[2,row-1] := points[1];
  astringgrid[currentplayerID *2].Cells[3,row-1] := points[2];

marabu 23. Jan 2007 06:31

Re: Stringrid Zeilen hinzufügen und löschen
 
Guten Morgen,

hier etwas Hilfe zur Selbsthilfe:

Delphi-Quellcode:
var
  i, iGrid, iRow: Integer;
  sg: TStringGrid;
begin
  // ...
  iGrid := currentplayerID * 2;
  if iGrid in Low(aStringGrid) to High(aStringGrid) then
  begin
    sg := aStringGrid[iGrid];
    if Assigned(sg) then
    begin
      iRow := (sg.RowCount);
      sg.RowCount := Succ(iRow);
      sg.Cells[0, iRow] := IntToStr(iRow);
      for i := Low(points) to High(points) do
        sg.Cells[Succ(i), iRow] := points[i];
    end else ShowMessage('grid missing')
  end else ShowMessage('grid index out of bounds');
  // ...
end;
Grüße vom marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz