Original Post
Ok, this is my problem:
I have a TStringGrid on a form with 100x100 cells - I need to add these cells into a text file. I do it using a nested for loop:
str := '''';
for y := 0 to 99 do
begin
for x := 0 to 99 do
begin
str := str+StringGrid1.Cells[x,y]+'',''; {adds a comma after}
{each entry for }
{easy parsing}
ProgressBar1.StepIt;
end;
memo1.lines.add(str);
str := '''';
end;
For those of you who don''t understand how it works it basically iterates through all the positions in the StringGrid1, adds them to a str (followed by a comma). After every x (row) adds the string to a memo component, and the resets the string. That way the memo1 looks just like the StringGrid, except with commas.
Here''s the problem: it doesn''t add all the lines of the StringGrid. So I added some debug lines. I made a debug window that had a TMemo component on it and I made the for loops add a line to it after every iteration.
For example, after the
str := str+StringGrid1.Cells[x,y]+'','';
I added
Form8.Memo1.Lines.Add(''Processed X-''+inttostr(x)+'' Y-''+inttostr(y));
I also added
StatusBar1.Panels[0].Text := ''X: ''+inttostr(x);
StatusBar1.Panels[1].Text := ''Y: ''+inttostr(y);
And then I displayed the memo1 contents - and used some code to count the lines.
Here is the crazy output for each of these Debug methods:
1 - The Form8 says that the processing was completed at:
X-78, Y-22.
I ran it again, and then after the X-78, Y-22 it went back to X-0 y-0. Wierd huh?
2 - The Status Bars say that it went to X:99 Y:99.
3 - There are 79 lines on the saver component.
----------
So then I tried a different coding technique. I used a listbox, and a memo2.
memo1.Clear; {<-New memo component}
listbox2.Clear;
for w := 0 to 99 do
listbox2.items.addstrings(stringgrid1.rows[w]);
z := 0;
for y := 0 to 99 do
begin
for x := 0 to 99 do
begin
str := str+ListBox2.Items.Strings[z]+'','';
z := z+1;
ProgressBar1.Stepit;
Form8.Memo1.Lines.Add(''Processed X-''+inttostr(x)+'' Y-''+inttostr(y));
end;
memo1.lines.Add(str);
str := '''';
end;
memo1.visible := true;
listbox2.visible := true;
saver.Lines.addstrings(memo1.lines); {TMemo}
save1.InitialDir := ExtractFileDir(save1.filename); {TSaveDialog}
saver.Lines.SaveToFile(save1.filename);
saver.Visible := true;
end;
progressbar1.Position := 0;
Form8.Memo1.ScrollBars := ssBoth;
Form8.Show;
end;
And these are the whacky return values:
Form8.Memo -> Same as the first method - 78,22
Saver1.Count -> 78 lines
Memo1.Count -> 79 Lines
HERES THE BIG ONE
10,000 entries into the ListBox, which means the problem lies with the transfer into the memo component.
-----------
Some thoughts of mine:
Memo1.Lines had a maximum entry length. Each line can hold 1074 characters - my largest lines (if all read ''[None]'' are in the upper 800''s. So it shoud fit with room to spare.
Something is messed up with the TStringGrid - nope, because it got all the information to the listbox. All 10,000 entries.
Nested for loops? I used the same format to initialize the StringGrid as well as about 100 otehr places in the program. All of which operate fine.
Well, I turn to you guys to see what you can do.
-DragonPhinn of Otakujin
Webmaster of http://www.thedragonlair.50megs.com
PS Source will be distributed upon request. I''d rather not though.