Lazarus

Free Pascal => Beginners => Topic started by: pentilisea on March 02, 2023, 06:00:32 pm

Title: Tricky Edit
Post by: pentilisea on March 02, 2023, 06:00:32 pm
Haya again

Running MX Linux.
Lazarus v2.0.12


I just learned how to fill a ListBox from a file  taking  only numbers and pass the ListBox Count to an Edit box and the last ListBox Item to another Edit. As well, deleting last Item without running into funny error messages.

I'm struggling with handling the Edit box.

1.Related to the picture, I need 37 Edit boxes (labeled 0 to 36).

2. If user clicks on say Edit labeled 3, it displays 1, if he clicks again, it displays 2, etc.

3. The value of the Edits are then saved into an array. Eventually this needs to be done without user input.

4. Then the label-number of the Edit (0 to 36) needs to be added  to another ListBox (for example: 3,3,4,7,14,34).

5.  The count of this ListBox will be added to a seperate Edit labeled "Bets" (in our example 6). So, user clicked 2 times on 3, then 4, 7, 14, and 34) - so user knows he has just betted 6 (€ or $)....
Finally the ListBox count is done to show in Edit labeled "Bets" need no further explanation.
I managed to convert the Edit values to integer and save them into an array (StrToInt) but failed to add them to a ListBox. The array is needed for further calculations.

However, don't want to waste your time needlesly.

In essence:
How to add 1 to an Edit by just clicking on it? (SpinEdit does not help - too cumbersome)

Then how to pass the content of the Edit to the array position [0..36] relevant to the Edit's label? Say Edit labeled 3 has 2 clicks, so number 2 must be saved to the array's position [3].

Each time the user clicks for example on Edit "number 3"  a 3 must be added to the ListBox. If he clicks 2 times on 3, there will be 2 Items 3 in the ListBox.

I'm bad in explaining, but maybe you're getting a sense of what I'm trying to achieve. It's simple stuff but I've got stuck somehow.

One or two lines of code would suffice to put me on my way .... or until next time .....

Thanks

Klaus



Title: Re: Tricky Edit
Post by: KodeZwerg on March 02, 2023, 06:07:42 pm
Edit seems to be wrong, use a SpeedButton or a plain Panel, having a simple OnClick event where "Inc()" is called for that array #, update caption, put caption to listbox etc etc etc...
Title: Re: Tricky Edit
Post by: KodeZwerg on March 02, 2023, 06:10:39 pm
If you need help with logic, upload your designed formular, i am really to lazy to do it.
Title: Re: Tricky Edit
Post by: pentilisea on March 02, 2023, 06:17:55 pm
Thanks Mr. Zwerg, will try and report....
Title: Re: Tricky Edit
Post by: pentilisea on March 07, 2023, 11:11:14 am
Got it!

Code: Pascal  [Select][+][-]
  1. begin
  2.  
  3.  Button12.Caption:= '';
  4.  
  5.  
  6.   ListBox2.Items.Add(label20.Caption);
  7.   go[8] := go[8] + 1;
  8.  
  9.   Button12.Caption := IntToStr(go[8]);
  10.   ListBox2.ItemIndex := ListBox2.Items.Count-1;
  11.  
  12.   Edit3.Text := IntToStr(ListBox2.Items.Count);
  13. end;              
  14.  
TinyPortal © 2005-2018