Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi StringGrid nach StrigGrid (https://www.delphipraxis.net/40984-stringgrid-nach-striggrid.html)

publes 24. Feb 2005 05:25


StringGrid nach StrigGrid
 
Wie kopiere ich in zwei unterschiedlichen Form's ein Grid in ein anderes Grid..........
beide heißen StringGrid2, das eine in der Form1 und das andere in der Form 2.........

Binärbaum 24. Feb 2005 06:42

Re: StringGrid nach StrigGrid
 
In etwa so:
Delphi-Quellcode:
var i, j: Integer;
begin
  Form2.StringGrid2.ColCount:= Form1.StringGrid2.ColCount;
  Form2.StringGrid2.RowCount:= Form1.StringGrid2.RowCount;
  for i:=0 to Form1.StringGrid2.ColCount-1 do
   for j:=0 to Form1.StringGrid2.RowCount-1 do
     Form2.StringGrid2.Cells[i,j]:= Form1.StringGrid2.Cells[i,j];
end;
MfG
Binärbaum

Sharky 24. Feb 2005 06:59

Re: StringGrid nach StrigGrid
 
Hai Binärbaum,

das ganze müsste auch mit einer Schleife gehen ;-)

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  ndx : Integer;
begin
  Form2.StringGrid2.ColCount:= Form1.StringGrid2.ColCount;
  Form2.StringGrid2.RowCount:= Form1.StringGrid2.RowCount;

  for ndx := 0 to StringGrid1.RowCount do
  begin
    Form2.StringGrid1.Rows[ndx] := Form1.StringGrid1.Rows[ndx];
  end;
end;

Binärbaum 24. Feb 2005 14:44

Re: StringGrid nach StrigGrid
 
Zitat:

Zitat von Sharky
Hai Binärbaum,

das ganze müsste auch mit einer Schleife gehen ;-)

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  ndx : Integer;
begin
  Form2.StringGrid2.ColCount:= Form1.StringGrid2.ColCount;
  Form2.StringGrid2.RowCount:= Form1.StringGrid2.RowCount;

  for ndx := 0 to StringGrid1.RowCount do
  begin
    Form2.StringGrid1.Rows[ndx] := Form1.StringGrid1.Rows[ndx];
  end;
end;

War mir fast schon klar, dass da jemand eine einfachere/ bessere Lösung hat. :) Die Frage ist nur, ob dieser Code auch wirklich schneller ist, da Rows ja auch auf die einzelnen Felder einer Zeile zugreifen muss, oder nicht? :gruebel:

Jasocul 24. Feb 2005 14:55

Re: StringGrid nach StrigGrid
 
imho werden da Speicherbereiche kopiert. Rows ist vom Typ TStrings. Daher sollte das schneller sein.
Das gleiche ginge auch mit Cols. Da man meistens weniger Cols als Rows hat wäre es damit vermutlich noch schneller.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:31 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