Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to sort items in TComboBox for Firemonkey ?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Jul 28, 2017 9:22 PM Last Post By: Yilmaz Yoru
aidan levy

Posts: 31
Registered: 7/6/16
How to sort items in TComboBox for Firemonkey ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 30, 2017 10:08 AM
In VCL TComboBox have property Sorted but in Firemonkey I`m not see it.
How to make strings sorted ?
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: How to sort items in TComboBox for Firemonkey ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 28, 2017 8:28 PM   in response to: aidan levy in response to: aidan levy
aidan levy wrote:
In VCL TComboBox have property Sorted but in Firemonkey I`m not see it.
How to make strings sorted ?

I couldn't find a good solution here, also very less details. You can use CompareText() function by comparing ComboBox1->ListItems[i]->Text

There is ComboBox1->ListItems->Sort(....) function but it is not clear how it works.

May be this example helps : http://mojelder.hatenablog.com/entry/2015/07/24/100846
https://gist.github.com/mojeld/b943bbdad88be22a1fd6

I try to run as below but has errors

//---------------------------------------------------------------------------
 
#include <fmx.h>
#pragma hdrstop
 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
 
enum _DummyType{};
template <typename INTF, typename Sorty,
	typename R,
	typename P1 = _DummyType,
	typename P2 = _DummyType>
 
class TAho : public TCppInterfacedObject<INTF>
{
private:
	Sorty callback;
public:
	TAho(Sorty _callback){}// : callback(_callback) {}
	INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);
 
	R __fastcall Invoke(P1* p1, P2* p2)
	{
		return callback(p1,p2);
	}
};
 
struct Sort_x{
	Sort_x(){}
	int operator()(TFmxObject* Left, TFmxObject* Right)
	{
		return CompareText((reinterpret_cast<TFmxObject *>(Left))->TagString,
			(reinterpret_cast<TFmxObject *>(Right))->TagString);
	};
 
};
 
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
 
 
 
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
		typedef TAho<TFmxObjectSortCompare,Sort_x,int, TFmxObject, TFmxObject> TAAAho;
	ComboBox1->ListItems->Sort(_di_TFmxObjectSortCompare(new TAAAho(Sort_x() )));
}
//---------------------------------------------------------------------------
 


Year 2017, and sorting items shouldn't be hard as shown above.

May be it is time to create your own sort function over ListItems :) Search Delphi examples and Firemonkey examples.

I hope that helps

--
Best Regards
Dr. Yilmaz Yoru
Esenja Company
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02