•
•
•
•
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 455,964 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,609 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: 1605 | Replies: 15 | Solved
![]() |
| |
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
All the help I have received in here has been wonderful and I am very glad that there are good people in here to help us newbies. I know I sure need it!
So these last few things would be nice to get some help with and then I will be done with this list modifier I have been working on for too long now. haha
1: Trying to sort a list from Z to A. I have A to Z done. I will post code if requested.
2: Sort a list numerically without it being sorted lexicographically. (thanks for that term Duoas)
3: Capitalize the first letter in a list of names... and/or capitalize all first letters on each word.
~I had some help from Duoas on that but I dont seem to be able to get it right. I cant seem to implement this on a button click. I have been trying all afternoon to do this and other things in this list i am writing up. -- s[ 1 ] := UpCase( s[ 1 ] );
4: Take each line in a loaded list and put it in reverse order. (i.e. 12345 will be 54321)
Thats about it. If this is too much for one post or I am not allowed to do this sort of thing, I will close this thread or a moderator can. I don't want to put silly questions in here at all.
Thanks for any help. BTW, this is all being done in a ListView.
So these last few things would be nice to get some help with and then I will be done with this list modifier I have been working on for too long now. haha
1: Trying to sort a list from Z to A. I have A to Z done. I will post code if requested.
2: Sort a list numerically without it being sorted lexicographically. (thanks for that term Duoas)
3: Capitalize the first letter in a list of names... and/or capitalize all first letters on each word.
~I had some help from Duoas on that but I dont seem to be able to get it right. I cant seem to implement this on a button click. I have been trying all afternoon to do this and other things in this list i am writing up. -- s[ 1 ] := UpCase( s[ 1 ] );
4: Take each line in a loaded list and put it in reverse order. (i.e. 12345 will be 54321)
Thats about it. If this is too much for one post or I am not allowed to do this sort of thing, I will close this thread or a moderator can. I don't want to put silly questions in here at all.
Thanks for any help. BTW, this is all being done in a ListView.
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation:
Rep Power: 6
Solved Threads: 68
Yes , please post the code first.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
Code is as follows:
1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.
I would like to also sort it from z - a... that is the problem atm...
2: Sort a list numerically... tried stdata..
this does not truly sort numerically...
3: Capitalize the first letter in a list or all first letters in a list... no idea. Not much luck on reading up on it. Most code I saw was applied to other edit boxes and not tlistview.
4: Reversing the order of a line in listview.. Cant get that to work either and looking it up hasn't afforded much help either. I was given this to start off with.
so there you have it.
im new
Thanks for any help...
1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.
delphi Syntax (Toggle Plain Text)
procedure TMainForm.SortListButtonClick(Sender: TObject); begin ListView1.SortType := stBoth; CurrentStatusLabel.caption := 'List Sorted'; end;
I would like to also sort it from z - a... that is the problem atm...
2: Sort a list numerically... tried stdata..
delphi Syntax (Toggle Plain Text)
ListView1.SortType := stData;
this does not truly sort numerically...
3: Capitalize the first letter in a list or all first letters in a list... no idea. Not much luck on reading up on it. Most code I saw was applied to other edit boxes and not tlistview.
4: Reversing the order of a line in listview.. Cant get that to work either and looking it up hasn't afforded much help either. I was given this to start off with.
delphi Syntax (Toggle Plain Text)
s[ 1 ] := UpCase( s[ 1 ] );
so there you have it.
im newThanks for any help...
Last edited by squidd : Nov 19th, 2007 at 2:39 am.
•
•
Join Date: Sep 2007
Posts: 69
Reputation:
Rep Power: 2
Solved Threads: 7
•
•
•
•
Code is as follows:
1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.
delphi Syntax (Toggle Plain Text)
procedure TMainForm.SortListButtonClick(Sender: TObject); begin ListView1.SortType := stBoth; CurrentStatusLabel.caption := 'List Sorted'; end;
I would like to also sort it from z - a... that is the problem atm...
2: Sort a list numerically... tried stdata..
delphi Syntax (Toggle Plain Text)
ListView1.SortType := stData;
this does not truly sort numerically...
3: Capitalize the first letter in a list or all first letters in a list... no idea. Not much luck on reading up on it. Most code I saw was applied to other edit boxes and not tlistview.
4: Reversing the order of a line in listview.. Cant get that to work either and looking it up hasn't afforded much help either. I was given this to start off with.
delphi Syntax (Toggle Plain Text)
s[ 1 ] := UpCase( s[ 1 ] );
so there you have it.im new
Thanks for any help...
Squidd, whenever you look up Delphi help - e.g. for SortType - also make sure that you check out the entries under See Also.
In this instance what you need is to checkout the OnCompare. event. You can use this event to alter the way the sort is being done. Here is some, untested, code that should do your reverse sort
procedure TMaster.WhenLVCompare(Sender:TObject;Item1,Item2:TListItem;Data:Integer;var Compare:Integer);
begin
Compare:=CompareText(Item2.Caption,Item1.Caption);
end;As to the problem with capitalization - remember that you will need to update the corrected entry in the listview. Thus if you have the code
procedure TMaster.InCapLV;
var i:Integer;
s:String;
AList:TListItems;
begin
AList:=lvOne.Items;
with AList do
for i:=0 to Count - 1 do
begin
s:=Item[i].Caption;
s[1]:=UpCase(s[1]);
Item[1].Caption:=s;
end;
end;you should get the result you desire.
As I have discussed before this is not really the right way to deliver speed nor to write good code. However, I guess that is the learning process you are currently going through.
p.s. - I guess I should have commented on the OnCompare event and the CompareText method
a. By default some Delphi controls, such as ListView, and controls, such as TStringList, know how to do a sort.
b. If you don't like the default sort order the offer - typically A -> Z - you can alter that by writing the OnCompare event.
c. CompareText is a unit in SysUtils - spend some time looking at the routines available in SysUtils. Could save you a lot of time. Here is what Delphi help says regarding CompareText
CompareText compares S1 and S2 and returns 0 if they are equal. If S1 is greater than S2, CompareText returns an integer greater than 0. If S1 is less than S2, CompareText returns an integer less than 0. CompareText is not case sensitive and is not affected by the current locale.
I think you will be able to figure out the rest.
Last edited by ExplainThat : Nov 19th, 2007 at 3:30 am.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
Working on it now.. Actually have been working on it for the last 2 hours.
I implemented your sample code for Capitalizing the first letter, but instead of doing all of them in the list, it caps the last line and moves that line up to and writes over the second line in a loaded list.
Looking into that right now. Thanks you for your help. And I am still using ListView1 for the name as that is the only LV i have in this program. I am not disregarding your advice, but the name ListView1 for this program is comfortable for my purposes. Thank you for your help on this.
The other questions you ahev answered will be addressed after I correct this one. One thing at a time.
I implemented your sample code for Capitalizing the first letter, but instead of doing all of them in the list, it caps the last line and moves that line up to and writes over the second line in a loaded list.
Looking into that right now. Thanks you for your help. And I am still using ListView1 for the name as that is the only LV i have in this program. I am not disregarding your advice, but the name ListView1 for this program is comfortable for my purposes. Thank you for your help on this.
The other questions you ahev answered will be addressed after I correct this one. One thing at a time.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
How do I get a function to work when I click a Button on my form?
I thought I was to put this up in private declarations. Then add a button to perform a stringreverse procedure.
Obviously, this isnt working for me. I dont know how to get a button click to do a function listed elsewhere. AGH!
Thanks for any help.
delphi Syntax (Toggle Plain Text)
function StringReverse(const AString : string): string;
I thought I was to put this up in private declarations. Then add a button to perform a stringreverse procedure.
delphi Syntax (Toggle Plain Text)
procedure TMainForm.ReverseOrderButtonClick(Sender:TObject); var s : string; begin s := Reversestring(s); end;
Obviously, this isnt working for me. I dont know how to get a button click to do a function listed elsewhere. AGH!
Thanks for any help.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
What you have written looks right. But just to make sure you got there correctly (which makes all the difference):
1. You added a button to your form and named it "ReverseOrderButton".
2. You either a) double-clicked the button on your form, or b) changed the object inspector to list events and double clicked the "OnClick" item
3. You added your code.
Yes, it does something. However, in the example posted you reverse an uninitialized local string. That is, a string that only exists in the ReverseOrderButtonClick function and which you did not
Try this to see what it does:
The same is true for any
Hope this helps.
1. You added a button to your form and named it "ReverseOrderButton".
2. You either a) double-clicked the button on your form, or b) changed the object inspector to list events and double clicked the "OnClick" item
3. You added your code.
Yes, it does something. However, in the example posted you reverse an uninitialized local string. That is, a string that only exists in the ReverseOrderButtonClick function and which you did not
s := "hello"; before reversing, and which you have not displayed before the procedure quits and the string disappears. So, while you have reversed the string '', it never gets displayed and it appears that nothing happens.Try this to see what it does:
Delphi Syntax (Toggle Plain Text)
procedure TMainForm.ReverseOrderButtonClick( Sender: TObject ); begin with ReverseOrderButton do Caption := StringReverse( Caption ) end;
Item[ x ].Caption.Hope this helps.
•
•
Join Date: Nov 2007
Posts: 87
Reputation:
Rep Power: 2
Solved Threads: 1
delphi Syntax (Toggle Plain Text)
private function StringReverse(const AString : string): string;
this wont stop giving me the following error:
E2065 Unsatisfied forward or external declaration: 'TMainForm.StringReverse'
I dont know why its doing that.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Final Year Project Ideas (Computer Science and Software Design)
- advice needed..please see (ASP.NET)
- Calling a PHP function from HTML menu (PHP)
- Pascal starter. (Pascal and Delphi)
- help with getting soda machine program running (C++)
- help with this prog (C++)
- Urgent help (Networking Hardware Configuration)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Shorting code lines within one loop
- Next Thread: Problem with dbExpress



Hybrid Mode