Solved

short comboBox

Posted on 2001-08-01
19
251 Views
Last Modified: 2010-07-27
I had some items in the TcomboBox->items-TStrings
there are option to sort it ????
the sort need to be visual only , not the number they represnt ?

thank
0
Comment
Question by:krelman
  • 6
  • 4
  • 2
  • +5
19 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 6339907
2 ways:
 #1 write sorting procedure
 #2 push items from items property to some instance of TStringList, use sort method then push data back to combobox
ziolko.
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6339958
Yes

Combobox1.Sorted := True;

:)
GEM
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6340141
yup, gem is right,

just set sorted to true before adding the items
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Accepted Solution

by:
marquinho earned 100 total points
ID: 6341111
Hi here is a example with a TStringlist
just copy and paste both files .dfm and .pas

.dfm

object Form1: TForm1
  Left = 123
  Top = 186
  Width = 634
  Height = 310
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 72
    Top = 80
    Width = 145
    Height = 21
    ItemHeight = 13
    TabOrder = 0
  end
  object Button1: TButton
    Left = 360
    Top = 48
    Width = 75
    Height = 25
    Caption = 'Load Stringlist'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 376
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Sort'
    TabOrder = 2
    OnClick = Button2Click
  end
end

.pas

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    xItems    : TStringList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

begin
  xItems:=TStringList.Create;
  xItems.Clear;
  xItems.Add('9');
  xItems.Add('8');
  xItems.Add('7');
  xItems.Add('6');
  xItems.Add('5');
  ComboBox1.Items:=xItems;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  xItems.Clear;
  xItems.Add('9');
  xItems.Sort;
  xItems.Add('8');
  xItems.Sort;
  xItems.Add('7');
  xItems.Sort;
  xItems.Add('6');
  xItems.Sort;
  xItems.Add('5');
  xItems.Sort;
  ComboBox1.Items:=xItems;

end;

end.
0
 
LVL 1

Expert Comment

by:marquinho
ID: 6341112
Hi here is a example with a TStringlist
just copy and paste both files .dfm and .pas

.dfm

object Form1: TForm1
  Left = 123
  Top = 186
  Width = 634
  Height = 310
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 72
    Top = 80
    Width = 145
    Height = 21
    ItemHeight = 13
    TabOrder = 0
  end
  object Button1: TButton
    Left = 360
    Top = 48
    Width = 75
    Height = 25
    Caption = 'Load Stringlist'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 376
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Sort'
    TabOrder = 2
    OnClick = Button2Click
  end
end

.pas

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    xItems    : TStringList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

begin
  xItems:=TStringList.Create;
  xItems.Clear;
  xItems.Add('9');
  xItems.Add('8');
  xItems.Add('7');
  xItems.Add('6');
  xItems.Add('5');
  ComboBox1.Items:=xItems;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  xItems.Clear;
  xItems.Add('9');
  xItems.Sort;
  xItems.Add('8');
  xItems.Sort;
  xItems.Add('7');
  xItems.Sort;
  xItems.Add('6');
  xItems.Sort;
  xItems.Add('5');
  xItems.Sort;
  ComboBox1.Items:=xItems;

end;

end.
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6341194
there is an interesting things for all experts :
------------------------------------------------

Sort method can not work for my language becouse we write from right not left therefor I always Set

Combobox1.Sorted := False;

and sort it myself

Also , one time that i need it , I made another component that sort right to left not left to right .

always I have problems like this.

I hope it was not boring for u.although this type of straing problems all always interesting for me ! ;-)

best regards
hamed
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6342295
Hamed it seems to me that if Borland was selling a product in your language they would have thought of the problem of the reveral of the writing or is this one of those mistakes like Chevrolet made when they came out with the Nova and tried to sell in Latin America?

I think... Nova means no go. :)
0
 

Expert Comment

by:GoodTimes
ID: 6342522
I'm experiencing the same difficulties in my language because we write from right to left, and only in Delphi 4 (I think) Borland thought of adding BiDiMode to its components (and also not to all of them). I hope that in a few years they would begin to take notice of Right-To-Left languages...

Omri
0
 
LVL 3

Expert Comment

by:rondi
ID: 6343634
Use TStringList's Objects property to store the data
that each string points to.
That way it doesn't matter how the strings are ordered/sorted - you can set combobox1.sorted := true;
and each item still points to the right data.

rondi
0
 

Author Comment

by:krelman
ID: 6343823
i have problem with this answer if
I write stored = true
It change the index of the string
for example
fff index 1
ddd index 2
ere  index 3

after i stored = true it change the index
and i will need to change all the program .
how can i do it const that i will not change the program
every time i add a string into the combobox

thank
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6344900
hamed & GoodTimes > I think sort method of TStringList use AnsiCompareText or AnsiCompareString so it should use Windows regional settings.
ziolko.
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6345064
hi gemarti , :-)))

hi Omri , where do you come from ? I tested your suggestion it did not work( at least at first try) but i think it must be the answer ( for me not krelman ;-) ) , if it was true it can be so useful becouse is in TControl witch is a very basic Object;

best regards
hamed
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6345163
hi ziolko , yes you are right . and i used that exactly in Delphi3 ( if i remember true becouse now i have not that comp becouse of HDD damaging ) for change my Component and i changed func calling at source code and maked a new component.

but about your comment , meybe it is true and windows regional setting can help but there is some little problems
the regional setting of win98 has not my language and also arabian language that i know is from right to left like our language ( although win2000 has it ) . another problem is i think dependenve of one language to regional setting is not good way.are you agree with me?

but if you are shur that regional setting can solve the problem please tell me !

thanks alot for your help
hamed
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6350412
Probably regional settings will help but only PROBABLY, basicly I don't "trust" Windows, so if there is way to do something independently from Windows (like sorting strings) I do that!!. There is many  good known sorting algorithms like QuickSort or HeapSort so it's really not a big problem to write Your own sorting procedure. (I supose TStringList's Sort method use QuickSort, but I'm not sure)
ziolko.
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6351119
hi ziolko ,thanks for your help. you are right TStringList uses QuickSort algorithm.I have used some Sort algorithm like QuickSort and i am agree with you, they are not hard.almost all of sort algorithms uses Compare func. and for problems like that mentioned just changing the used compare func. can be enouph.

anyway . i read your profile. I am 22 ( like you ) and a senior student of Electrical Control Eng.math is so intersting for me . I am glad to be friend with you.

best regards
hamed
0
 

Expert Comment

by:GoodTimes
ID: 6351219
Hamed,
I'm from Israel. Where are you from?

Omri
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6351342
hi Omri,
I am from Iran.

hamed
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6355552
That's one of reasons why I like Internet: people from all around the world!!
Hamed it's pleasure to me !!
ziolko.
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6358200
hi ziolko,i am agree with you.
please give me your e-mail , also you can see my e-mail in my profile.

Hamed
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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