Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

method to keep list of strings scrolled to bottom-some progress 1

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB
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:
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)
 
try this

put a stringgrid and a button on the form
set stringgrids options goEditing & goAlwaysShowEditor to true

then buttononclick put
Code:
  stringgrid1.setfocus;
  stringgrid1.rowcount := stringgrid1.Rowcount+1;
  stringgrid1.Cells[0,stringgrid1.Rowcount-1] := '';
  stringgrid1.row := stringgrid1.Rowcount -1;

Aaron
 
Aaron, many thanks for the reply!

The two settings to true fixed my exception error.
I would never have found that...

Very much appreciated.

Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top