Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Tstringlist do something each 10 records ?



Permlink Replies: 3 - Last Post: Mar 18, 2018 4:04 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
madammar ellias

Posts: 111
Registered: 8/17/17
Tstringlist do something each 10 records ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2018 1:32 AM
i have tstringlist with 1000 items i want to show result of each 10 items in the list is it possible ?
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Tstringlist do something each 10 records ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2018 2:04 AM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i have tstringlist with 1000 items i want to show result of each 10
items in the list is it possible ?

Your question is a bit vague. You can show any item from the stringlist
you want, since the list can be accessed by index, in any sequence you
like.

If you want to display the content in "pages" of 10 items, where the
user triggers the move to the next page by clicking a button or such,
you just have to remember the index of the last item you showed on the
current page, e.g. using a form-level variable (a private field). That
would start at -1 to indicate that the display has not been filled yet.

Let's call this field

FLastItemIndex: Integer;

You set it to -1 in the form's OnCreate event.

Let's assume you display the 10 items of a page in a TMemo, called
PageMemo. The you would add a method to the form like

procedure TFormX.ShowNextPage(aList: TStringlist);
var
I: integer;
begin
PageMemo.Lines.BeginUpdate;
try
PageMemo.Clear;
for i:= 1 to 10 do begin
Inc(FLastItemIndex);
if FLastItemIndex < aList.Count then
PageMemo.LInes.Add(aList[FLastItemIndex])
else
Break;
end;
finally
PageMemo.Lines.EndUpdate;
end;
end;

Its is much easier to just assign the complete list to PageMemo.Lines
and let the control handle the scrolling like it is designed to do,
using its scrollbars. Do not design a desktop application like a web
page, that just places unnecessary limitation on the user.

--
Peter Below
TeamB
madammar ellias

Posts: 111
Registered: 8/17/17
Re: Tstringlist do something each 10 records ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 18, 2018 4:02 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
Your question is a bit vague. You can show any item from the stringlist
you want, since the list can be accessed by index, in any sequence you
like.

If you want to display the content in "pages" of 10 items, where the
user triggers the move to the next page by clicking a button or such,
you just have to remember the index of the last item you showed on the
current page, e.g. using a form-level variable (a private field). That
would start at -1 to indicate that the display has not been filled yet.

Let's call this field

FLastItemIndex: Integer;

You set it to -1 in the form's OnCreate event.

Let's assume you display the 10 items of a page in a TMemo, called
PageMemo. The you would add a method to the form like

procedure TFormX.ShowNextPage(aList: TStringlist);
var
I: integer;
begin
PageMemo.Lines.BeginUpdate;
try
PageMemo.Clear;
for i:= 1 to 10 do begin
Inc(FLastItemIndex);
if FLastItemIndex < aList.Count then
PageMemo.LInes.Add(aList[FLastItemIndex])
else
Break;
end;
finally
PageMemo.Lines.EndUpdate;
end;
end;

Its is much easier to just assign the complete list to PageMemo.Lines
and let the control handle the scrolling like it is designed to do,
using its scrollbars. Do not design a desktop application like a web
page, that just places unnecessary limitation on the user.

--
Peter Below
TeamB

i just wanted to show 10 results each time instead of 1 result each time , this simply cannot be achived in delphi your code also will show one line each loop and as extra its count the loop the rest of text i did not understand it thanks any ways
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Tstringlist do something each 10 records ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 18, 2018 4:04 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:

i just wanted to show 10 results each time instead of 1 result each
time

Show them how, though? What do you want to show them in? You gave
NO DETAILS in your original question. So Peter gave you one *possible
example*, but that does not necessarily mean that it is appropriate for
your own code. Without ANY details about what you are trying to
acheive, we can't really help you very much.

this simply cannot be achived in delphi

Of course it can. It is just a matter of coding it properly.

your code also will show one line each loop

Look again. It loops through the StringList adding 10 lines to the
Memo and then stops so the user can see them. When the function is
called again, it shows the next 10 lines and then stops. And then the
next 10 lines. And so on.

as extra its count the loop the rest of text i did not understand it

What exactly do you not understand? You need to be more specific.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02