Recent

Author Topic: Help with TComboBox  (Read 4062 times)

aacury

  • Newbie
  • Posts: 4
Help with TComboBox
« on: October 31, 2018, 07:45:07 pm »
Hi guys,

I've just started working with Lazarus and I've got a simple (I guess) question:

I'm creating a TCombobox with 5 items. What I want is: when the user chooses one of the items, an input dialog appears so the user can input three or four values (that will be used later in my code).

Thus, my question is: how do I make an input dialog appear when a given TCombox item is selected?

Many thanks,
Alex

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help with TComboBox
« Reply #1 on: October 31, 2018, 08:36:25 pm »
Thus, my question is: how do I make an input dialog appear when a given TCombox item is selected?

Add a handler for the ComboBox.OnSelect event, check which item was selected with ComboBox.Items[ComboBox.ItemIndex] (or just ComboBox.ItemIndex if the order is predefined) and execute the proper dialog.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

aacury

  • Newbie
  • Posts: 4
Re: Help with TComboBox
« Reply #2 on: November 01, 2018, 01:54:39 pm »
Thanks for your help. The handler did the trick.

However, which command should I call for the input dialog? (I need one so the user can input three or four values that will be used later in my code)

Thanks again.

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Help with TComboBox
« Reply #3 on: November 01, 2018, 02:07:53 pm »
Thanks for your help. The handler did the trick.

However, which command should I call for the input dialog? (I need one so the user can input three or four values that will be used later in my code)

Thanks again.

You should design the dialog yourself for your need. Is is rather easy in Lazarus (start with File->New Form from the main menu).
Of course there are no predefined input dialogs for every situation. See what is offered here: http://wiki.freepascal.org/Dialog_Examples#Text_input_Dialogs


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help with TComboBox
« Reply #4 on: November 01, 2018, 03:03:28 pm »
However, which command should I call for the input dialog? (I need one so the user can input three or four values that will be used later in my code)

You should design the dialog yourself for your need. Is is rather easy in Lazarus (start with File->New Form from the main menu).

Another handy trick is to implement your dialogs as frames instead of forms; that way you can use just one "dialog" form showing the correct frame. It's a little more work (though not that much) but allows you to reuse those same frames elsewhere if you change your UI type at some future time.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

aacury

  • Newbie
  • Posts: 4
Re: Help with TComboBox
« Reply #5 on: November 01, 2018, 06:58:55 pm »
Hi guys,

thanks again for the help. I managed to make it work.

However, like I said, I need an input dialog for three or four user inputs. It seems that both InputBox and InputQuery accept just the one, right?

Is there any simpler way to create such thing and store the inputs in a vector?
« Last Edit: November 01, 2018, 07:47:27 pm by aacury »

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Help with TComboBox
« Reply #6 on: November 01, 2018, 07:05:42 pm »
Yes. You need to design a form with X inputs with fsDialog style. This not complex. Try that first yourself. We will give an example if you can not figure it out.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help with TComboBox
« Reply #7 on: November 02, 2018, 01:21:24 am »
As a teaser, here is a 10 minutes, Q&D example of how it may look :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

aacury

  • Newbie
  • Posts: 4
Re: Help with TComboBox
« Reply #8 on: November 02, 2018, 09:53:18 am »
As a teaser, here is a 10 minutes, Q&D example of how it may look :D

Did you use the fsDialog mentioned by Thaddy?

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Help with TComboBox
« Reply #9 on: November 02, 2018, 11:05:22 am »
As a teaser, here is a 10 minutes, Q&D example of how it may look :D

Did you use the fsDialog mentioned by Thaddy?

Before asking, you tried with and without fsDialog yourself of course, didn't you? What differences did you notice?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Help with TComboBox
« Reply #10 on: November 02, 2018, 01:34:17 pm »
Did you use the fsDialog mentioned by Thaddy?

Yes, I did; they're no much different in this theme (Oxygen-GTK) but p.e. note the lack of "maximize" button. Zoran is right: try it yourself and look.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018