User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 456,233 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,767 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 5517 | Replies: 46 | Solved
Reply
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #11  
Nov 7th, 2007
You didn't define save250 the way I gave it to you. The one you defined takes a single argument: a TObject. The one I gave you takes entirely different arguments.

The procedure header should look like this:
procedure SaveNLines( filename: string; var strs: tStrings; startAt, numLines: integer );
Please notice how I renamed the procedure from save250 to saveNLines.

Hope this helps.
Last edited by Duoas : Nov 7th, 2007 at 4:38 pm.
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #12  
Nov 7th, 2007
sigh... i cant get this to compile... *bangs head against the wall*

I copy your exact line changed it to SaveNLines where needed, and back to save250, then to AGGHH... no avail...
Last edited by squidd : Nov 7th, 2007 at 5:16 pm.
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #13  
Nov 7th, 2007
Here is what I have now....

Procedure Header:
procedure SaveNLines( filename: string; var strs: tStrings; startAt, numLines: integer );

Code For Button12:
procedure TForm1.Button12Click(Sender: TObject);
var
lines_per_block: integer;
line_index: integer;
file_number: integer;
file_extension: string;
base_filename: string;
begin
lines_per_block := StrToInt( edit6.text ); // number of lines to save per file
if saveDialog1.execute then
begin
// get the file extension and everything except the extension in
// separate strings so we can inject the 1, 2, 3, ... file number.
file_extension := extractFileExt( saveDialog1.filename );
base_filename := copy( saveDialog1.filename,1,length( saveDialog1.filename ) -length( file_extension ));
// save each block of lines
line_index := 0;
file_number := 1;
while line_index < ListView1.items.count do
begin
SaveNLines(base_filename + intToStr( file_number ) + file_extension,
ListView1.items, line_index, lines_per_block);
inc( file_number );
inc( line_index, lines_per_block );
end;
end;
end;

And the errors that inevitably ensue when I attempt to compile:
[DCC Error] : E2065 Unsatisfied forward or external declaration: 'TForm1.SaveNLines'
[DCC Error] : E2033 Types of actual and formal var parameters must be identical

I simply have no idea why this is happening... I really appreciate your patience and help on this matter regardless of whether or not I can get this work for me.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #14  
Nov 7th, 2007
Don't bang your head too hard... you don't want to break it.

Unsatisfied forward or external declaration
You can declare a thing and you can define a thing:
  1. unit fooey;
  2. interface
  3. // Everything in this section is a DECLARATION
  4. function hum( bark: string ): string;
  5.  
  6. implementation
  7. // Everything this section is a DEFINITION
  8. function hum( bark: string ): string;
  9. begin
  10. result := 'Baz says "' + bark + '"'
  11. end;
  12.  
  13. end.
An Object Pascal unit requires you to first declare your functions, etc. in the interface section. Then you must use the implementation section to define the thing things you declared. If you do not define it, but only declare it, then you are basically telling the compiler that some function exists when it does not.


The type of things matters
Recall that I previously recommended you to use something other than a TListView? (such as a TListBox)? That is because the items property is a TListItems, not a TStrings. The former is weird and hard to handle. The latter is convenient and easy to handle. Unless you are making a spreadsheet or something you should not be using a TListView.

The procedure I gave you takes a TStrings, not a TListItems. If you insist on using a TListView then you will have to convert your items property into a TStrings object before using the function I gave you. If you don't want to do that either then you will have to get every string out of the items property and write it to file in a loop.


Tell me what you want to do and I'll help you proceed. But I'll also expect you to spend a little more time thinking about it first... Don't feel bad. I am not trying to make this hard for you. Honest.

Hope this helps.
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #15  
Nov 8th, 2007
I want to do this is in listview... Not listbox.. List box will be my next endeavor.

I thought I was clear on wanting this done in ListView at the very start. If not, my apologies. The whole program uses ListView and would require and enormous amount of time to switch everything to a ListBox.

I am new at this, and this one thing and remove duplicate entries are the only things left to complete this project. In listView, not Listbox.

Thank you for your help and patience with a newbie.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #16  
Nov 8th, 2007
Alright. Here's a SaveNLines that takes a TListItems.
  1. procedure saveNLines(
  2. filename: string;
  3. var items: tListItems;
  4. startAt: integer;
  5. numLines: integer
  6. );
  7. var
  8. sl: tStringList;
  9. b, e: integer;
  10. begin
  11. // Our temporary string list
  12. sl := tStringList.create;
  13. // indices of lines to copy, inclusive
  14. b := startAt;
  15. e := startAt + numLines -1;
  16. if e >= items.count then e := items.count -1;
  17. // copy the indexed lines into our temporary string list
  18. for b := b to e do
  19. sl.append( items.item[ b ].caption );
  20. // save the lines to file
  21. sl.saveToFile( filename );
  22. // cleanup
  23. sl.free
  24. end;
Notice that nothing other than each item's caption is saved to file.

Sorry for the confusion. P.S. I haven't tested this code. It might need a tweak here or there.
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #17  
Nov 8th, 2007
And this will split files and begin a save sequence when I click button12?

It looks like it is a procedure that does not have the button being used at all. Let me give it a go however and thank you very much.

ok here is what I did and I think maybe a tweak or two may be needed as you mentioned earlier... I am glad this is so easy for you.. it sure isnt for me.

Added to types:

procedure saveNLines( filename: string; var items: tListItems; startAt: integer; numLines: integer );

Added to the button12 to perform the action of splitting files:
procedure TForm1.Button12Click(Sender: TObject);
var
sl: tStringList;
b, e: integer;
begin
// Our temporary string list
sl := tStringList.create;
// indices of lines to copy, inclusive
b := startAt;
e := startAt + numLines -1;
if e >= items.count then e := items.count -1;
// copy the indexed lines into our temporary string list
for b := b to e do
sl.append( items.item[ b ].caption );
// save the lines to file
sl.saveToFile( filename );
// cleanup
sl.free
end;
end;

And the resulting compile errors:

[DCC Error] : E2029 ')' expected but identifier 'item' found
[DCC Error] : E2003 Undeclared identifier: 'items'
[DCC Error] : E2003 Undeclared identifier: 'numLines'
[DCC Error] : E2003 Undeclared identifier: 'startAt'

Looks like this is getting much closer to working now even though there are errors... Also, what about my edit6.text being used to determine the number of lines to split the list into? Or am I missing something in what you coded?
Last edited by squidd : Nov 8th, 2007 at 5:40 pm.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #18  
Nov 8th, 2007
I'd like to help more but at this point you aren't paying attention. I've given you all the code you need --which is much more than I usually do. You have to use your brain now and use the code I've given you correctly.
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #19  
Nov 8th, 2007
uhm.. ok

thanks for your help
Reply With Quote  
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #20  
Nov 8th, 2007
Anyone else to take a stab at solving this?

Seems this gentleman has given up...

In my defense, the code posted on page one was not correct at all and was to be used in a ListBox procedure (which probably isnt not a bad idea at all).. Regardless, once that was straightened out, I get more code that doesn't work. If I knew how to do this, I wouldn't be asking. While I appreciate the person's help and his apparent 'above and beyond' normal helping. The problem is no closer to being solved that when I first posted my question for help.

Thanks for any future help regarding this 'evidently' easy task.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 5:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC