Recent

Author Topic: Can't show a TstringList to a combo box  (Read 12940 times)

donnie

  • Jr. Member
  • **
  • Posts: 72
Can't show a TstringList to a combo box
« on: March 08, 2010, 11:46:31 am »
I have added some items to a StringList.The items are loaded normal(I write them to a log file).
But when I add them to my combo box (and built it for my PDA)
for i := 0 to mainform.countStringList-1 do
      begin
      combobox.items.add(mainform.TStringList[i]);
      end;


the combo box is empty.
Does anyone know how to fix it and show them in the same language with my TstringList?
« Last Edit: March 08, 2010, 12:13:43 pm by nek »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Can't show a TstringList to a combo box
« Reply #1 on: March 08, 2010, 02:46:15 pm »
Looks like your file isn't encoded in UTF-8, you can either encode the file in UTF-8 or convert upon loading, here a simple idea:

for i := 0 to mainform.countStringList-1 do
      begin
      combobox.items.add(AnsiToUTF8(mainform.TStringList));
      end;

There are better routines for conversion in Lazarus, but I don't remember the unit name or the routine names =D Should be easy to find searching Lazarus sources.

Lazarus controls always require the strings to be UTF-8 encoded

jagorath

  • New Member
  • *
  • Posts: 34
Re: Can't show a TstringList to a combo box
« Reply #2 on: March 08, 2010, 07:36:37 pm »
You can also use the TStrings.Assign method -
Code: [Select]
combobox.items.Assign(mainform.TStringList);

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: Can't show a TstringList to a combo box
« Reply #3 on: March 09, 2010, 08:19:03 am »
It does work now in windows but still not in my PDA.The AnsiToUtf8 works fine in windows( to work the Assign() must be encoded to utf8 first with AnsiToUtf8).To my PDA with AnsiToUtf8 it shows me something but the letters are like...chinese.The English letters are ok!But the others(Greek) are not(Maybe doesn't support Greek???)!Thank you very much both.You've been very helpful!
« Last Edit: March 09, 2010, 12:42:40 pm by nek »

Zoran

  • Hero Member
  • *****
  • Posts: 1882
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Can't show a TstringList to a combo box
« Reply #4 on: March 09, 2010, 12:53:15 pm »
It does work now in windows but still not in my PDA.The AnsiToUtf8 works fine in windows( to work the Assign() must be encoded to utf8 first with AnsiToUtf8).To my PDA with AnsiToUtf8 it shows me something but the letters are like...chinese.The English letters are ok!But the others(Greek) are not(Maybe doesn't support Greek???)!Thank you very much both.You've been very helpful!

No, no, no. UTF8 certanly does support Greek, only AnsiToUTF8 does not know that your file uses greek code page! If you know that your file will always be Greek, then here is what you should do:

First, add LConvEncoding unit to uses list.
Then, instead of AnsiToUTF8, use CP1253ToUTF8 (Greek is probably encoded with Win1253 code page).
So, this should work for you:
Code: [Select]
combobox.items.add(CP1253ToUTF8(mainform.TStringList));
« Last Edit: March 09, 2010, 12:56:04 pm by Zoran »

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: Can't show a TstringList to a combo box
« Reply #5 on: March 09, 2010, 12:58:31 pm »
Amazing man!!!!Many many many thanks....
It worked perfect.....!!!! :) :) :) :)

 

TinyPortal © 2005-2018