•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
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
my provider is
Use whatever compression program you like (ZIP, TGZ, RAR, etc.) I won't take EXEs though.
michael thomas greer (without the spaces)my provider is
comcast.netUse whatever compression program you like (ZIP, TGZ, RAR, etc.) I won't take EXEs though.
•
•
Join Date: Nov 2007
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 1
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.
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
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
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. 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
you will wind-up asking at some point, "what does button1 do again?". However:
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.
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:
Delphi Syntax (Toggle Plain Text)
procedure TForm1.Button1Click(Sender: TObject); // load/open file var txt : TextFile; Buffer : String; begin if openDialog1.Execute() then //(1) begin AssignFile(txt, openDialog1.FileName); Reset(txt); while NOT EOF(txt) do begin ReadLn(txt, Buffer); ListView1.Items.Add.Caption := trim(Buffer); end; ListView1.Columns[0].Caption := inttostr(ListView1.items.Count); //(2) CloseFile(txt); end; end;
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
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.
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
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:
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:
If that doesn't fix it then I'm completely baffled...
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 thenso 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:
Delphi Syntax (Toggle Plain Text)
try lines_per_block := strToInt( edit6.text ) except showMessage( 'You must specify how many lines to save per file' ); edit6.setFocus; exit end;
If that doesn't fix it then I'm completely baffled...
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
•
•
Join Date: Nov 2007
Posts: 70
Reputation:
Rep Power: 1
Solved Threads: 1
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!
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!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- printing of sort list (C++)
- Recrusive Split on a linked list (C)
- Something is very very strange about my IE. Perhaps it's a spyware...Please help me!! (Viruses, Spyware and other Nasties)
- Taskmgn.exe adware? (Viruses, Spyware and other Nasties)
- PC crashes (Viruses, Spyware and other Nasties)
- Spyware is Redirecting Homepage (Viruses, Spyware and other Nasties)
- IE6 has been constantly hijacked by .... (Viruses, Spyware and other Nasties)
- Microsoft IE Offline Pop-ups (Web Browsers)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Disassembly pane, CPU Window
- Next Thread: Package GXOUTLOOK



Linear Mode