| View previous topic :: View next topic |
| Author |
Message |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Mon May 05, 2008 6:10 am Post subject: [Delphi] reading through tMemo lines |
|
|
so i've got this code:
| Code: | | for i := 0 to MemoActions.Lines.Count - 1 do |
to count through my lines, but how do i determine if im on the last line?
i tried to do
| Code: | if i + 1 = MemoActions.Lines.Count then
begin
//do stuff
end; |
i think i might but just a little bit wrong, but how do i get it to work?
_________________
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 05, 2008 6:46 am Post subject: |
|
|
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to MemoActions.Lines.Count - 1 do
begin
if i = MemoActions.Lines.Count -1 then
ShowMessage('Last line')
else
ShowMessage('Line:'+IntToStr(i+1));
end;
end; |
This will say "Last line" if it's the last line and "Line: <linenumber>" if it's not.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Mon May 05, 2008 6:58 am Post subject: |
|
|
thanks, lemme try
_________________
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 474
Joined: 09 May 2003 Posts: 25968 Location: The netherlands
|
Posted: Mon May 05, 2008 7:42 am Post subject: |
|
|
also, if you're obsessed about gaining an almost unnoticeable speed gain:
| Code: |
for i := 0 to MemoActions.Lines.Count - 2 do
begin
ShowMessage('Line:'+IntToStr(i+1));
end;
i:=MemoActions.Lines.Count -1;
ShowMessage('Last line');
|
This way it'll have one less compare in the loop
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
haha01haha01 Grandmaster Cheater Supreme
Reputation: 0
Joined: 15 Jun 2007 Posts: 1233 Location: http://www.SaviourFagFails.com/
|
Posted: Mon May 05, 2008 8:41 am Post subject: |
|
|
| Dark Byte wrote: | also, if you're obsessed about gaining an almost unnoticeable speed gain:
| Code: |
for i := 0 to MemoActions.Lines.Count - 2 do
begin
ShowMessage('Line:'+IntToStr(i+1));
end;
i:=MemoActions.Lines.Count -1;
ShowMessage('Last line');
|
This way it'll have one less compare in the loop |
Lol, so predictable of u trying to make the shortest and fastest code
|
|
| Back to top |
|
 |
|