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 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
Reply
Join Date: Nov 2007
Posts: 87
Reputation: squidd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
squidd squidd is online now Online
Junior Poster in Training

A few questions to finish up my project

  #1  
Nov 18th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is offline Offline
Veteran Poster

Re: A few questions to finish up my project

  #2  
Nov 19th, 2007
Yes , please post the code first.
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #3  
Nov 19th, 2007
Code is as follows:

1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.

  1. procedure TMainForm.SortListButtonClick(Sender: TObject);
  2. begin
  3. ListView1.SortType := stBoth;
  4. CurrentStatusLabel.caption := 'List Sorted';
  5. end;

I would like to also sort it from z - a... that is the problem atm...

2: Sort a list numerically... tried stdata..

  1. 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.

  1. s[ 1 ] := UpCase( s[ 1 ] );

so there you have it. im new

Thanks for any help...
Last edited by squidd : Nov 19th, 2007 at 2:39 am.
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: A few questions to finish up my project

  #4  
Nov 19th, 2007
Originally Posted by squidd View Post
Code is as follows:

1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.

  1. procedure TMainForm.SortListButtonClick(Sender: TObject);
  2. begin
  3. ListView1.SortType := stBoth;
  4. CurrentStatusLabel.caption := 'List Sorted';
  5. end;

I would like to also sort it from z - a... that is the problem atm...

2: Sort a list numerically... tried stdata..

  1. 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.

  1. 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.
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #5  
Nov 19th, 2007
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.
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #6  
Nov 19th, 2007
I found the problem with the capitalization of the first letter.

the line:

Item[1].Caption := s;

should be

Item[i].Caption := s;

now it works perfectly.


Also, I am going to try and capitalize any first letter in my list now. Thanks again for your help... You too Duoas!
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #7  
Nov 20th, 2007
I have the list capitalizing as it should now.. the code is probably poor, but it works...

I will now work on reversing the items in my listview.. but that will wait until tomorrow, I have spent a lot of time going back and undoing error correction the didnt work.

Thanks again!
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #8  
Nov 20th, 2007
How do I get a function to work when I click a Button on my form?

  1. 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.

  1. procedure TMainForm.ReverseOrderButtonClick(Sender:TObject);
  2. var
  3. s : string;
  4. begin
  5. s := Reversestring(s);
  6. 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.
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: A few questions to finish up my project

  #9  
Nov 20th, 2007
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 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:
  1. procedure TMainForm.ReverseOrderButtonClick( Sender: TObject );
  2. begin
  3. with ReverseOrderButton do
  4. Caption := StringReverse( Caption )
  5. end;
The same is true for any Item[ x ].Caption.

Hope this helps.
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 online now Online
Junior Poster in Training

Re: A few questions to finish up my project

  #10  
Nov 20th, 2007
  1. private
  2.  
  3. function StringReverse(const AString : string): string;
  4.  

this wont stop giving me the following error:

E2065 Unsatisfied forward or external declaration: 'TMainForm.StringReverse'

I dont know why its doing that.
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 9:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC