I've found a method on Torry's Delphi pages to 'position the caret in a stringgrid', which actually works, before it raises an exception :-(
Below is my procedure, which is loading the same delimted text file into a StringGrid and a Stringlist.(This is to evaluate the two, one will be removed when I think I have the best 'container')
When I add the lines in red, at runtime I get an access violation, Read of address 00000000.
It does actually do what I want, which is display the StringGrid scrolled to the last item, before the problem.
I have the type statement:
higher up in my code.
Is there something wrong I'm doing?
And is there a similar method for StingList I could use?
Here's the procedure:
Steve (Delphi 2007 & XP)
Below is my procedure, which is loading the same delimted text file into a StringGrid and a Stringlist.(This is to evaluate the two, one will be removed when I think I have the best 'container')
When I add the lines in red, at runtime I get an access violation, Read of address 00000000.
It does actually do what I want, which is display the StringGrid scrolled to the last item, before the problem.
I have the type statement:
Code:
TGridCracker = class(TStringGrid); [COLOR=green]//for setting strigGrid caret position[/color]
higher up in my code.
Is there something wrong I'm doing?
And is there a similar method for StingList I could use?
Here's the procedure:
Code:
procedure TSDIAppForm.Button1Click(Sender: TObject);
var
line, col : integer;
ListItem: TListItem;
begin
[COLOR=green]//will load the comma delimited TXT here[/color]
CallBase := TStringList.Create;
[COLOR=green]//will process each TAB delimited line here[/color]
CallBaseRow := TStringList.Create;
CallBaseRow.Delimiter := #44; [COLOR=green]//comma[/color]
CallBaseRow.QuoteChar := '|';
try
[COLOR=green]//load the comma delimited txt file[/color]
CallBase.LoadFromFile('test.csv') ;
StringGrid1.RowCount := CallBase.Count;
ListView1.Items.BeginUpdate;
[COLOR=green]//for each comma delimited line[/color]
for line := 0 to -1 + CallBase.Count do
begin
if Line>0 then ListItem := ListView1.Items.Add(); [COLOR=green]// Adds a new row to Listview1[/color]
CallBaseRow.DelimitedText := CallBase[line]; [COLOR=green]//"load" the line into a stringlist[/color]
for col := 0 to -1 + CallBaseRow.Count do
begin
StringGrid1.Cells[col,line] := CallBaseRow[col]; [COLOR=green]//add each column of row to stringgrid[/color]
if Line>0 then [COLOR=green]//miss out first row of column headings[/color]
begin
if col=0 then ListItem.Caption := CallBaseRow[col] else ListItem.SubItems.Add(CallBaseRow[col]);
end;
end;
end;
ListView1.Items.EndUpdate;
[COLOR=red]
StringGrid1.SetFocus;
StringGrid1.Col := 0;
StringGrid1.Row := line-1;
with TGridCracker(StringGrid1) do
InPlaceEditor.SelStart := 1;[/color]
finally
[COLOR=green]//CallBaseRow.Free;[/color]
[COLOR=green]//CallBase.Free;[/color]
end;
AutoSizeGrid(StringGrid1);
end;
Steve (Delphi 2007 & XP)