Recent

Author Topic: [SOLVED] What device to use to pick choice of a few integer numbers?  (Read 9505 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
I want to have like a drop-down menu that would allow a user to choose integer numbers 1, 2, 3, 4, 5, 6, which would then be the decimal places for formatting folating point results of a certain TfloatspinEdit display (which already has a property for decimal places), or to format the value when shown anywhere, for instance. Just a click at the number would be all that would be needed. No editing. Just click on the number so it goes somewhere where I can catch it. I also need to know WHERE that'd be.

So I've tried and tried to see which component to put in the form that would allow the said choice of 6 integers above, but am stumped.

Thanks, I hope it's a simple request, for you all, but it's got me down for quite a while. :(
 

« Last Edit: July 24, 2011, 01:42:53 am by Elmug »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: What device to use to pick choice of a few integer numbers?
« Reply #1 on: July 23, 2011, 11:09:36 am »
Naive option: combobox with six values. But it's not pretty. Same could be done with a listbox, which might be a bit prettier.

Other option: groupbox with 6 radio buttons, labelled 1..6

Silly option: textbox, and validate so only 1..6 are accepted

And I'm sure the UX/UI experts will have many better suggestions....
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: What device to use to pick choice of a few integer numbers?
« Reply #2 on: July 23, 2011, 10:35:08 pm »
Naive option: combobox with six values. But it's not pretty. Same could be done with a listbox, which might be a bit prettier.

Other option: groupbox with 6 radio buttons, labelled 1..6

Silly option: textbox, and validate so only 1..6 are accepted

And I'm sure the UX/UI experts will have many better suggestions....

Thanks for the reply BigChimp, and others.
   
In my little project, I did think, tried, and studied the use of a list box.

So I still have there a list box into which i entered

Columns = 1 (Still don't know what Columns is for, though),

and in Items (string type), I entered 1 2 3 4 5 6 each numbered followed by the Return or Enter key. So, if the item list is a string, I suppose the string contains the Enter key char value.

So when I run the program, I can scroll up and down and click on any of those numbers, and each number becomes highlighted.

No I can't figure out what the clicking or highlighting amounts-to so I can use that knowing and use it in some code.

I understand the list is a string, and that I have clicked a part of that string, so when the user highlights the string, what is actually happening? Where does the effect reflect so  I can use the effect in some code?

Further, I am not sure if there's other properties of the ListBox that are critical in what I am trying to do, as described in this post.
   
Some basic help is most welcome on this. Also, where can I study how these items are to be used? Sometimes not being familiar with some terminology makes searching difficult. What I'd appreciate is a link to where I can learn how the Standard and the Misc and other components are meant to be used, things about their properties, and so on. Also, if there is a book that explains these things I think I should get it so I don't have to ask some of these questions, nor use so much time in trying to find out. Any suggestions?

Thanks!

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: What device to use to pick choice of a few integer numbers?
« Reply #3 on: July 24, 2011, 01:41:39 am »
Good people,

I've got this sorted out.

I found a good webpage
http://www.delphibasics.co.uk/Article.asp?Name=Standard
that explains quite well what I was lacking and was asking about.

The list box has a property called index and that index is an integer, so in this case I can use that property since the first choice is 1 the second is 2 and so forth, the index integer will be identical to the choice value, with no need to manipulate strings to digits or similar things.

I suppose combo boxes works in a similar way with "indexes" and I was not also aware of creating and using a variable of the type TListBox.

I think I can handle it  from there.

Thanks!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [SOLVED] What device to use to pick choice of a few integer numbers?
« Reply #4 on: July 24, 2011, 09:02:41 am »
Yes, Delphibasics's a very good site that I've been plugging in my posts, too  :)

Other info (hope others can append to this):
  • Forum member motaz has written a very clear manual/tutorial for FreePascal/Lazarus: "Start programming using Object Pascal": see post at http://lazarus.freepascal.org/index.php/topic,12926.0.html, book available, also as PDF, at http://code.sd/startprog/index.html
  • As Lazarus is mostly Delphi compatible: Delphi online help at , especially the pages under Delphi Reference
  • Marco Cantu www.marcocantu.com has written Essential Pascal and Essential Delphi: nice introductions.
  • You can download the Delphi 6 developer's guide; it covers using forms controls, etc. A lot, especially the basics, of it is applicable to Lazarus.
  • I also found an "Object Pascal Reference Guide" for Delphi for Windows floating on the net. Has more examples on using Pascal compared to the FreePascal documentation, which is more of a formal description
  • About.com, article Understanding the Birth, Life and Death of a Delphi Form: deals with events occurring during the life of a form. Also very much applicable to Lazarus. They have other good articles.
  • The wiki has a lot of information
  • FreePascal documentation

***modified 7 September: added online Delphi docs for all you forum searchers ;) ***
IIRC, the string values you entered separated by an enter are entered in a stringlist. The result is that you have a sort of array (in fact a stringlist) with 6 strings: 1 2 3 4 5 6. No carriage returns/linefeeds in there.

Yes, you can use the index property, but in many cases you'd prefer to use the actual value the user selected, even if you have to convert it from a string to an integer. What if you decide to sort them differently, or get your listbox values from an external source where you don't know the index?
« Last Edit: September 07, 2011, 08:08:09 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: [SOLVED] What device to use to pick choice of a few integer numbers?
« Reply #5 on: July 24, 2011, 09:10:19 am »
Thank you very much BigChimp for all your good suggestions.

The example cited from DelphiBasics was very valuable to me. It was an eye opener.

I worked on it for like a whole day, figuring it out and testing it, and then I discovered that I don't need to cast into a variable of the type of the object!

I can directly access the Index value with an assign statement, even though the Index is not a property shown in the properties box!

I verified that because the contents of the list is not a STRING with Enter (chr 13) included, but it is actually an ARRAY of strings, and so the Index CAN be accessed directly!

HOWEVER, all of that effort was great learning, but THEN, I discovered that my best choice was SIMPLY to use a TSpinEdit component, which itself holds INTEGERS, a value, and a min and max values...Precisely what I needed with less sweat and tears. :-[

I have put the links you now mention in my folder of references.

Thanks a lot!

 

TinyPortal © 2005-2018