Peter Kiers
asked on
A tstringlist - question
Hi there,
I want to load the text of a file in a stringlist, and that i allready did:
procedure TForm2.Button4Click(Sender : TObject);
var
sl: TStringList;
begin
sl := TStringList.Create;
try
sl.LoadFromFile(edit1.text );
mainform.Memo1.SetSelTextB uf(PChar(s l.Text));
finally
sl.Free;
end;
end;
But now I have 2 questions:
Is this possible to make a keydown-event and every time I press the arrow-
down button I get to see the first string in the statusbar. And when I press
again I get the next string etc.. etc... until end of string.
or
Is it perhaps possible to skip the stringlist, and just everytime I press the
arrow-down button the programm reads the first line of the textfile
and when I press again the second line until eof.
If its possible i prefer the second option.
Peter Kiers
Peter Kiers
I want to load the text of a file in a stringlist, and that i allready did:
procedure TForm2.Button4Click(Sender
var
sl: TStringList;
begin
sl := TStringList.Create;
try
sl.LoadFromFile(edit1.text
mainform.Memo1.SetSelTextB
finally
sl.Free;
end;
end;
But now I have 2 questions:
Is this possible to make a keydown-event and every time I press the arrow-
down button I get to see the first string in the statusbar. And when I press
again I get the next string etc.. etc... until end of string.
or
Is it perhaps possible to skip the stringlist, and just everytime I press the
arrow-down button the programm reads the first line of the textfile
and when I press again the second line until eof.
If its possible i prefer the second option.
Peter Kiers
Peter Kiers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I dont know if i did something wrong but I made this and i got an access violation:
var
MainForm: TMainForm;
iCurStr: integer;
sl: TStringList;
procedure TMainForm.Button3Click(Sen der: TObject);
begin
sl := TStringList.Create;
try
sl.LoadFromFile(edit1.text );
Memo1.text := sl.text;
finally
sl.Free;
end;
end;
procedure TMainForm.Button4Click(Sen der: TObject);
begin
if Opendialog1.Execute then
Edit1.Text:=Opendialog1.Fi leName;
end;
procedure TMainForm.FormKeyDown(Send er: TObject; var Key: Word;
Shift: TShiftState);
begin
if iCurStr = sl.count then exit;
inc(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
procedure TMainForm.FormKeyUp(Sender : TObject; var Key: Word;
Shift: TShiftState);
begin
if iCurStr = 1 then exit;
dec(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
peter
var
MainForm: TMainForm;
iCurStr: integer;
sl: TStringList;
procedure TMainForm.Button3Click(Sen
begin
sl := TStringList.Create;
try
sl.LoadFromFile(edit1.text
Memo1.text := sl.text;
finally
sl.Free;
end;
end;
procedure TMainForm.Button4Click(Sen
begin
if Opendialog1.Execute then
Edit1.Text:=Opendialog1.Fi
end;
procedure TMainForm.FormKeyDown(Send
Shift: TShiftState);
begin
if iCurStr = sl.count then exit;
inc(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
procedure TMainForm.FormKeyUp(Sender
Shift: TShiftState);
begin
if iCurStr = 1 then exit;
dec(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
peter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
procedure TMainForm.FormKeyDown(Send er: TObject; var Key: Word;
Shift: TShiftState);
begin
if sl.count = 0 then exit; //at this line i get an access violation
if key = VK_DOWN then
begin
if iCurStr = sl.count then exit;
inc(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end
else
if key = VK_UP then
begin
// check if at first position
if iCurStr = 1 then exit;
// if not at first position then put in status bar and deccrement count
dec(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
end;
Shift: TShiftState);
begin
if sl.count = 0 then exit; //at this line i get an access violation
if key = VK_DOWN then
begin
if iCurStr = sl.count then exit;
inc(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end
else
if key = VK_UP then
begin
// check if at first position
if iCurStr = 1 then exit;
// if not at first position then put in status bar and deccrement count
dec(iCurStr);
StatusBar1.Panels[0].text := (sl.strings[iCurStr-1]);
end;
end;
that is becaus in button3 click, you not just create sl, but also free it, so sl is no longer initialized ;)
better create sl and formcreate and destroy it at formdestroy ;)
better create sl and formcreate and destroy it at formdestroy ;)
ASKER
Thanx. Problem solved.
Peter Kiers
Peter Kiers
ASKER