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,610 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,507 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: 5526 | 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

  #21  
Nov 8th, 2007
There's no need for the angry attitude or to get all defensive. I have far more experience than you and, whether you believe it or not, a greater understanding of your problem than you do.

At no point have I given you incorrect code --all the code I supplied works fine. The problem lies in your understanding.

May I ask how it is that you have written so much code that it would take an enormous amount of time to switch to a TListBox (which, you will note, I have not required you to do), without understanding the basic concepts central to programming? At no point have I written anything in any post of mine which does not directly apply to your efforts. Don't just skip over stuff you don't understand because you think it has no bearing.

You are perfectly capable of working with what I have given you. It is neither over your head nor is it smarter than you. You must, if you intend to continue working with Delphi, learn how to lookup information about the VCL with the Delphi help system, and you must understand how to create and use procedures and functions, and you must understand how the type of a thing affects the code used to manipulate it. Failing these things you will remain stuck.

It is time now to put a little effort into learning something about these things instead of demanding that I or anyone else simply give you code to cut and paste (which, BTW, I have already done). Programming is not easy. It takes a lot of work, and years to become sufficiently proficient that tasks like this become 'evident'.

I have already said, and remain, willing to help. But I am unwilling to do your work for you.
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

  #22  
Nov 8th, 2007
Wasnt getting defensive nor angry... You are not willing to help me get this one thing complete or understand what I am not doing correctly. I have spent hours on looking up information to get this done before posting this question here.

I am VERY new to programming... I am doing this alone on my own time at home. I never said you were not more experienced than me. So please. Just stop posting and turning this post into a completely unnecessary flame war.

Thanks (again) for your help. But it wasnt enough to help me understand why i cant get it to work. You are right, I am wrong. Now please let someone else with better communication skills try to help me out with this should they choose to. If I understood why I cant get it to work, then I wouldnt be typing still.

Have a nice day kind sir.
Last edited by squidd : Nov 8th, 2007 at 7:23 pm. Reason: spelling
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

  #23  
Nov 8th, 2007
Look, I haven't meant to make you feel stupid.

1. Look at posts #4 and #10, where I gave you an event handler and which you correctly modified to use the TListView.
2. Now look at post #16 where I gave you a function that prints x lines from a TListView's item list.
3. Put them both in your code. Change the word "save250" from post #10 to "saveNLines".


I know you are new to programming. That is why I have asked you to read about procedures and about types. All your errors are due as a direct consequence of your failure to do that.

You are being defensive and angry. And you presume too much to say I am unwilling or that I misunderstand. I understand better than you think, and I have stated repeatedly I am willing to help, if you are willing to follow the advice given you. I have no interest in wasting my time to lead you in circles.

Please consider that I know what it is to learn how to program and how much information overload it is to find simple answers. The truth is that there are no simple answers when it comes to programming, and you are going to have to wrap your mind around a few things --none of which come easily-- to get it right. Until you do, even a gift horse looks like a mule.
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

  #24  
Nov 9th, 2007
1. Look at posts #4 and #10, where I gave you an event handler and which you correctly modified to use the TListView.
2. Now look at post #16 where I gave you a function that prints x lines from a TListView's item list.
3. Put them both in your code. Change the word "save250" from post #10 to "saveNLines".

And again, after all this is done.. it wont compile.. still.

[DCC Error] : E2065 Unsatisfied forward or external declaration: 'TForm1.saveNLines'
[DCC Error] : E2197 Constant object cannot be passed as var parameter

Even after I did EXACTLY what you recommend, it doesnt compile.. has never compiled.

I simply don't know how to correct these errors. I cant make plainer than that.

EDIT:

Also, I have to say. If this is what I have to go through to learn one single thing for each thing I try to do, then I dont know how much longer I am going to bother with learning how to program. I have spent an ENORMOUS amount of time trying to figure this single procedure out, and the effort is simply not worth the payoff in this case i am starting to think. You cannot even begin to comprehend my frustration with this. I am getting REALLY pissed. Not at you so much, but at the idea that a simple thing such as this is so much trouble. Almost a week on this ONE thing.
Last edited by squidd : Nov 9th, 2007 at 5:31 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

  #25  
Nov 9th, 2007
Yeah, I know. I've gone through the same things... Over and over and over again. It's just part of programming...

Post your entire unit and I'll take a look-see. It has to be something painfully silly.

I once spent an entire week on about 60-70 lines of C code and was just at the point of burning my PC when I figured out that I had misplaced a } somewhere. Most. Obnoxious. Error. Ever.

Things get better after a while. Honest they do. Just don't give up. (Right now I'm banging my own head against the windows console... the stupid thing doesn't have a WndProc, permit event hooks, anything... it is for all intents and purposes an actual GUI-less process. All I want to know is if the user grabs the window and sizes it... but apparently that "can't happen". Alas...)


I think you put the saveNLines inside your TForm1 class definition, but defined it below as
procedure saveNLines( ... );
instead of
procedure TForm1.saveNLines( ... );

I'm not sure what the second error is, so post everything so I can find it.
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

  #26  
Nov 9th, 2007
I don't think I need to post the entire program.. its almost 300 lines. Which I know is nothing, but it works fine without the code in question. See if you can find out what is wrong here first. If not Ill post the whole thing.


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


private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject); 
begin
  Form1.Caption := 'List Modify';
  ListView1.Columns.Add.Caption := '0';
  Listview1.Columns[0].Width := 300;
end;


  1. procedure TForm1.Button12Click( Sender: TObject );
  2. var
  3. lines_per_block: integer;
  4. line_index: integer;
  5. file_number: integer;
  6. file_extension: string;
  7. base_filename: string;
  8. begin
  9. lines_per_block := strToInt( edit6.text ); // number of lines to save per file
  10. if saveDialog1.execute then
  11. begin
  12. // get the file extension and everything except the extension in
  13. // separate strings so we can inject the 1, 2, 3, ... file number.
  14. file_extension := extractFileExt( saveDialog1.filename );
  15. base_filename := copy( saveDialog1.filename,1,length( saveDialog1.filename ) -length( file_extension ));
  16. // save each block of lines
  17. line_index := 0;
  18. file_number := 1;
  19. while line_index < ListView1.items.count do
  20. begin
  21. SaveNLines(base_filename + intToStr( file_number ) + file_extension,
  22. ListView1.items, line_index, lines_per_block);
  23. inc( file_number );
  24. inc( line_index, lines_per_block );
  25. end;
  26. end;
  27. end;
  28.  
  29. procedure TForm1.saveNLines(filename: string; var items: tListItems; startAt: integer; numLines: integer);
  30. var
  31. sl : tStringList;
  32. b, e : integer;
  33. begin
  34. // Our temporary string list
  35. sl := tStringList.create;
  36. // indices of lines to copy, inclusive
  37. b := startAt;
  38. e := startAt + numLines -1;
  39. if e >= items.count then e := items.count -1;
  40. // copy the indexed lines into our temporary string list
  41. for b := b to e do
  42. sl.append( items.item[ b ].caption );
  43. // save the lines to file
  44. sl.saveToFile( filename );
  45. // cleanup
  46. sl.free
  47. end;

I hope you can find the problem.... I am bummed out. Thanks again
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

  #27  
Nov 9th, 2007
OK, that was enough. You need two changes.

In your class definition:
  1. private
  2. { Private declarations }
  3. procedure saveNLines(filename: string; items: tListItems; startAt: integer; numLines: integer);
  4. public
  5. { Public declarations }
  6. end;
You must declare your procedures and functions before you can use them. Also, the compiler was complaining about passing the TListView.items as a var argument, so you will notice that I removed the var from the parameter list. The actual procedure definition must match, so change it below the same way:
  1. procedure TForm1.saveNLines(filename: string; items: tListItems; startAt: integer; numLines: integer);

That compiled and worked correctly for me.
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

  #28  
Nov 9th, 2007
yes SIR! It did compile! Thank you very much

But nothing happens when I add a number to the edit6.text box and click button12 to perform the now correct (thank you very much for that btw) code.

What is missing I wonder to where the button (button12) isnt doing the procedures being called upon?

I am happy at this point to just have it compile. But the splitting of a large list still doesnt happen .

I loaded up a list of over 15,000 lines. and clicked the button. Nothing happened. I say ok fine.. no problem. so I load up a list again and type in '20' in edit6.text. Then I went to the save button, and it didn't split it up there either.

maybe I should post the whole thing for you to peruse. This is insane. lol
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

  #29  
Nov 9th, 2007
It works, it just doesn't tell you it did. Check your directory for files.

Remember also that the TListView must be populated with at least one item for it to work. (You loaded your list so that's not a problem.) When I did it, I just added three items using the designer, set the number of items per file to 2, and clicked the button --producing two files (the first containing two lines and the last containing one). I'm sure you must have a ton of files in the directory you saved to.

Most programs indicate that a save worked successfully by putting a message on the statusbar or changing the main form's caption or some other like thing.

Another thing you should be aware of is that there is currently no error checking to make sure that Edit6 contains a number, so if the user puts in "fooey" the program will crash. Go ahead and try it. There are several ways to fix this, but the easiest is something like:
  1. try
  2. lines_per_block := strToInt( edit6.text )
  3. except
  4. showMessage( 'You must specify how many lines to save per file.' );
  5. edit6.setFocus;
  6. exit
  7. end;
  8. if saveDialog1.execute then ...

Glad to be of 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

  #30  
Nov 9th, 2007
it doesn't split the file nor does it save to the folder where the original file was loaded from. Actually, after added a value i.e. 50 to edit6.text, I then clicked button12 (after compiling all this first of course) and nothing happens.. Nothing is being split. If it is, then why isnt it saving?

Is that another thing altogether? Thanks again.

and yes, error checking is definately something I will need to do and possibly will help with, but no need for that until i get this to work. lol
Last edited by squidd : Nov 9th, 2007 at 11:36 pm. Reason: spelling
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 7:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC