Solved

Delphi / Firemonkey Combo Box values, possable?

Posted on 2014-01-21
11
4,369 Views
Last Modified: 2014-06-02
Hi,

I want to have a selected value that is different than the displayed value?

It is possible to do this in HTML and in .net.

Is it possible to do this in Delphi/FireMonkey Mobile?

When I go into the ComboBox Items Designer it only shows a place to enter the display text.

Likewise in the Object Inspector, the Combo Box items look more like ListView items with text only, no values.

My desire is to have unique values for the displayed items that can be stored in a DB table and used against a lookup table.

I would also like to have the combo items populated form that same lookup table, but I don't see any way to do that with Live Bindings.

Gary
0
Comment
Question by:Gary4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39798609
You can use livebinding...
http://edn.embarcadero.com/article/41708
But there is a problem that binding use just 200 items.

I prefer custom filling (binding do same internally).
This can be don in Delphi/FireMonkey too.
  ComboBox1.Items.Clear;

  ADODataSet1.First;
  while not ADODataSet1.Eof do
  begin
    ComboBox1.Items.AddObject(
      ADODataSet1.FieldByName('ItemName').AsString,
      TObject(ADODataSet1.FieldByName('ItemId').AsInteger)
      );

    ADODataSet1.Next;
  end;

Open in new window


... selected item id you can get as:
if Assigned(ComboBox1.Selected) then
    ShowMessage(IntToStr(Integer(ComboBox1.Selected.Data)));

Open in new window


my dataset is looking ...
select ItemName,Itemid from mytable order by 1

Open in new window



As I can see live binding is more a problem than a solution.
0
 
LVL 1

Author Closing Comment

by:Gary4
ID: 39801251
I found an article that told how to do it with Live Bindings and I did it that way.  I wasn't' particularly intuitive because of the field names used.

However, your code did help me with some other issues I had.
0
 
LVL 1

Author Comment

by:Gary4
ID: 40104306
@Sinisa Vuk

Hi,

I came back to this for the same problem on another project.  This time I used your solution since I couldn't use Live Bindings this time.

I wish I could give you 500 more points and up the rating!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40104356
Glad that my comment helps ....
0
 
LVL 1

Author Comment

by:Gary4
ID: 40104457
Hi,

Sorry to be a pest, however,

There seems to be a problem in my code.

This code is in a data module.  The control is passed in from a from.  The control is on the form.

InterestTB  is a FireDac FDTable on the data module.

procedure TChirpMaxDB.FillddChannel(ddChannel: TComboBox);
var
  I: Integer;
  sb: string;
begin
  ddChannel.BeginUpdate;
  ddChannel.Items.Clear;
  with InterestTB do
  Begin
    Active := True;
    First;
    while (not Eof) do
    begin
      I := FieldByName('ID').AsInteger;
      sb := FieldByName('Name').AsString;
      ddChannel.Items.AddObject(sb, TObject(I)); // <-- It fails on this line on the first iteration.
      Next;
    End;
    Active := False;
  End;
  ddChannel.ItemIndex := 0;
  ddChannel.EndUpdate;
  ddChannel.Repaint;
end;

Open in new window


Any thoughts?

The code ran fine with win32 as the target.

It's failing with Android as the target.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40104945
Why don't you say - android? :-)

Unfortunately, .AddObject doesn't work on android/ios. Had same problem too.
Read this on this blog and how to overcome this:
http://blogs.riversoftavg.com/index.php/2013/08/01/using-primitive-types-with-tstrings-in-ios/
0
 
LVL 1

Author Comment

by:Gary4
ID: 40105206
I did say Firemonkey, implying cross platform. :-)

One would think they would throw a compile error rather then leaving it laying around to trip over like some scripting language.

The again, one would think if they knew about it they would 'make' it work like they did other things.

I spent about ten years with .net and never thought twice about 'boxing', except as a possible performance penalty.

Thanks again :-)

I think this is now my go to place for Delphi/Firemonkey help.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40105246
No problem. As I'm sw developer with full time job (using Delphi), sometimes I come to problems before others :-)
0
 
LVL 1

Author Comment

by:Gary4
ID: 40105263
I'm a full time developer too, I find it objectionable to stumble over problems in my development tools.

In this case the compiler is generating bad code and if storing an integer as an object is not part of the language it should have thrown an error.

I spent 12 hours futzing with this.  Time I should have spent making a TEdit scroll.

Are you part of the hire-a-pro thing they recently announced?
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40105276
No, maybe will be in future :-) couse I'm short with time these days....
0
 
LVL 1

Author Comment

by:Gary4
ID: 40105294
Fair enough.  I was only thinking of short term things that stump me. Maybe of a day or less. I didn't have anything in mind right now.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question