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 423,511 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 4,652 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: 5073 | Replies: 46 | Solved
Reply
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
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: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #31  
Nov 9th, 2007
I can't reproduce your error. If you can't figure it out by tomorrow then go to your project directory, zip everything up, and send it to me at
michael thomas greer (without the spaces)
my provider is
comcast.net

Use whatever compression program you like (ZIP, TGZ, RAR, etc.) I won't take EXEs though.
Reply With Quote  
Join Date: Nov 2007
Posts: 70
Reputation: squidd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #32  
Nov 9th, 2007
will do man... Thank you for all of your help twith this.. Also, I was thinking that when button12 was clicked that a save function would happen to allow the person to name the basefilename and then increment after that.

I doubt I will be able to fix this tonight or ever so i am going to zip it up and send it to you now.

Cant thank you enough for your efforts. Also, I am going out tomorrow and will be buying a book or two on delphi coding for idiots like me for a reference and reading material.

Noone should have to go through this much to get one simple thing to work. Likewise, noone should have to help this much over something like this.

Sending the file to you now as I have been unable to do a thing with it.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
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: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #33  
Nov 10th, 2007
You sent that to me so quickly I took a look at it already. I still can't reproduce your error --the program works fine for me.


Testing
Are you sure you are saving in the same directory you loaded from? Here is what I did:
click "Load List", select my input file "in.txt". The list loads.

My list had twelve items, so I put something like 5 in the edit box. (I also tested with 4. As part of your error checking you need also to make sure that the number in the edit box is strictly greater than 1.)

I click "Go" to save. I select the same directory I loaded from and type an output file name "out.txt". Using explorer (or the command prompt) I look at the directory and I see three files:
- out1.txt
- out2.txt
- out3.txt
Examining the files shows they are properly formed.

The load and save directory need not be the same. Even if you load something the save directory is still at the default directory. You can force them to match by saying
saveDialog1.initialDir := extractFileDir( openDialog1.filename );
before calling saveDialog1.execute.


Some errors
My debugger complained about a couple of things, so I looked them over. They are all in Button1Click. Here it is fixed:
  1. procedure TForm1.Button1Click(Sender: TObject); // load/open file
  2. var
  3. txt : TextFile;
  4. Buffer : String;
  5. begin
  6. if openDialog1.Execute() then //(1)
  7. begin
  8. AssignFile(txt, openDialog1.FileName);
  9. Reset(txt);
  10. while NOT EOF(txt) do
  11. begin
  12. ReadLn(txt, Buffer);
  13. ListView1.Items.Add.Caption := trim(Buffer);
  14. end;
  15. ListView1.Columns[0].Caption := inttostr(ListView1.items.Count); //(2)
  16. CloseFile(txt);
  17. end;
  18. end;
1. If openDialog1.execute returns successfully, the filename will never be an empty string. You will notice I used the same pattern when I used saveDialog1.execute in the code I gave you.
If you just execute, then test the filename, the filename could be anything. Even if the user clicks cancel, if filename is not '' then you'll load the same file again.

2. There is no need to spam the application with updates for every line you load. Set the caption after all the files have loaded, and let the application process messages at its own convenience. It is relatively rare that you need to tell it otherwise.

Your formatting style (indentation and the like) is a bit unique (which is fine) but also a little random. I tend to want all statements "belonging" to another statement (such as a loop or procedure) to be indented under that statement. For example, I type "procedure", then everything under that is indented two spaces. Since the "begin" doesn't belong to "var", both have the same level of indentation. This tells me at a glance which statements belong to what.

Also, you should get into the habit of immediately naming things when you add them. I know that a lot of tutorials and books and code people post use Button1 and Edit2 and the like, but numbers tell you nothing about the function of the object. For example, you could name Button1 as one of the following: BtnLoadList, LoadListButton, etc. It doesn't really matter how you do it as long as you are consistent. When you see
procedure Button1Click(Sender: TObject);
you will wind-up asking at some point, "what does button1 do again?". However:
procedure LoadListButtonClick(Sender: TObject);
is immediately apparent.


Epilogue
I haven't tested all the other buttons in your application, just load list, edit6, and Go button 12. Again, I cannot reproduce your error --It works fine for me.

It is possible that the problem you have is related to the errors produced by the button1click procedure that I made note of above. If that doesn't fix it and you don't have other code in there I don't know about then I don't know what else could be wrong...

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

Re: How to split a large list

  #34  
Nov 10th, 2007
so you are saying when you click the go button (button12) a save window comes up? That doesnt happen for me. The files may be all set to go, but I cant save them for some reason. isnt that just odd....

I sent you the entire program too...

hmmm. I cant understand that.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
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: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #35  
Nov 10th, 2007
Yes, it gives the dialogue and all.

Ah, I forgot to mention that your program shouldn't have compiled at all because you had listed in your uses clause unit1 instead of unit1_helpme. So I'm not sure exactly what is wrong.

I used Delphi 5 to compile it. You said you were using FPC? Give me a day and I'll see if I can make it work with FPC.
Reply With Quote  
Join Date: Nov 2007
Posts: 70
Reputation: squidd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #36  
Nov 10th, 2007
I am using CodeGear RAD Studio 2007, and I renamed the project to help me for sending to you. It is without the helpme on the end after that.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
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: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #37  
Nov 11th, 2007
I've looked over the sources you sent me again and I can't see why it shouldn't work.

CodeGear bought Borland's Delphi and C++ IDE/compilers, so you are actually using Delphi 2007 (the latest version) to compile your code.

The OnClick for Button12 is properly set to Button12Click in the DFM file, and the procedure itself does:
lines_per_block := strToInt( edit6.text );
if saveDialog1.execute then
so there is no valid reason why the dialogue shouldn't appear... except if edit6 contains an invalid number.

Why don't you change the first line to this and see if it catches the error:
  1. try lines_per_block := strToInt( edit6.text )
  2. except
  3. showMessage( 'You must specify how many lines to save per file' );
  4. edit6.setFocus;
  5. exit
  6. end;

If that doesn't fix it then I'm completely baffled...
Reply With Quote  
Join Date: Nov 2007
Posts: 70
Reputation: squidd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #38  
Nov 11th, 2007
I emailed you again about an hour ago. I would like you to see if what I sent you actually works as well. Let me know when you have some free time. Thanks for your help.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
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: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to split a large list

  #39  
Nov 11th, 2007
Replied in kind. Lots of little fixes, a couple big ones. Most by way of suggestion and organization.

Let me know if your problem disappears with the changes.
Reply With Quote  
Join Date: Nov 2007
Posts: 70
Reputation: squidd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
squidd squidd is offline Offline
Junior Poster in Training

Re: How to split a large list

  #40  
Nov 12th, 2007
ok this is merely a reply just to say that I have a bigger reply in the very near future... it is late and I just want to tell you how much I appreciate your help with tis. the problem IS solved. and I will reflect that after my next post...

I just want to read everything you wrote many more times and grasp it all. And the only problem I am having is simply getting the program to add the .txt extension at the end of the newly split list names.

this problem is SOLVED by DUOAS!
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 4:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC