•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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:
Please notice how I renamed the procedure from save250 to saveNLines.
Hope this helps.
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.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
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.
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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:
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.
Unsatisfied forward or external declaration
You can declare a thing and you can define a thing:
Delphi Syntax (Toggle Plain Text)
unit fooey; interface // Everything in this section is a DECLARATION function hum( bark: string ): string; implementation // Everything this section is a DEFINITION function hum( bark: string ): string; begin result := 'Baz says "' + bark + '"' end; end.
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.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
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.
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
Alright. Here's a SaveNLines that takes a TListItems.
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.
Delphi Syntax (Toggle Plain Text)
procedure saveNLines( filename: string; var items: tListItems; startAt: integer; numLines: integer ); 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;
Sorry for the confusion. P.S. I haven't tested this code. It might need a tweak here or there.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
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?
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
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.
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.
![]() |
•
•
•
•
•
•
•
•
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