Recent

Author Topic: [SOLVED] (MEMO)s in my TDBComboBox  (Read 911 times)

Slyde

  • Full Member
  • ***
  • Posts: 152
[SOLVED] (MEMO)s in my TDBComboBox
« on: June 16, 2022, 05:49:38 pm »
I can't get rid of these things.  I know that you have to enable dgDisplayMemoText in Option of the TDBGrid in the Object Inspector to get rid of them, but TDBComboBox doesn't have that flag.  I'm using it to load names from a SQLite3 db table, which is populated, and all I get is the (MEMO) in place of the names.  I can't ever recall a TDBComboBox displaying (MEMO) in place of the actual data.  But this one is.

Any ideas/suggestions?

« Last Edit: June 17, 2022, 12:57:11 pm by Slyde »
Linux Mint 21.3
Lazarus 3.0

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: (MEMO)s in my TDBComboBox
« Reply #1 on: June 16, 2022, 07:39:04 pm »
You probably assigned to the DBCombobox a field which is a memo. If you have the possibility to change the field definitions change it to a string field of fixed length. If this is not possible you can assign a handler for the OnGetText event to the memo field. Assign the result of the field's AsString property to the string output variable of the handler:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CommentsGetTextHandler(Sender: TField; var aText: string;
  2.   DisplayText: Boolean);
  3. begin
  4.   AText := Sender.AsString;
  5. end;

See attached demo.

Zvoni

  • Hero Member
  • *****
  • Posts: 2329
Re: (MEMO)s in my TDBComboBox
« Reply #2 on: June 17, 2022, 08:13:58 am »
wp,
SQLite doesn't have a Memo-Type for its fields

OP,
change your SQL to
Code: SQL  [Select][+][-]
  1. SELECT CAST(MyTextField AS CHAR) AS MyField FROM TABLE

And no, using SELECT * FROM Table is not an excuse for you.....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: (MEMO)s in my TDBComboBox
« Reply #3 on: June 17, 2022, 11:49:27 am »
@Zvoni:

I wasn't using SELECT * for my query.  Just the one field.  However, in using your suggestion, the DBComboBox still loaded with (MEMO)s.  This is what I have for it:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ReloadComboBox;
  2. begin
  3.   DBComboBox1.Clear;
  4.   ZQ2.Close;
  5.   ZQ2.SQL.Text := 'SELECT CAST(name AS CHAR) AS nameField FROM pupils';
  6.   ZQ2.Open;
  7.   ZQ2.First;
  8.   while not ZQ2.EOF do
  9.   begin
  10.     if ZQ2.FieldByName('nameField').AsString <> '' then
  11.       DBComboBox1.Items.Add(ZQ2.FieldByName('nameField').DisplayText);
  12.     ZQ2.Next;
  13.   end;
  14.   DBComboBox1.Sorted := True;
  15. end;

I'm not sure what else to do.  One wld think this wldn't be an issue in 2022, that this wld've been ironed out years ago.  But here we are, still fighting it.
Linux Mint 21.3
Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2329
Re: (MEMO)s in my TDBComboBox
« Reply #4 on: June 17, 2022, 12:13:32 pm »
Try
Code: SQL  [Select][+][-]
  1. SELECT CHAR(MyTextField) AS NameFIeld FROM TABLE
I remember having that too, and i think i solved it that way (not with CAST)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: (MEMO)s in my TDBComboBox
« Reply #5 on: June 17, 2022, 12:56:35 pm »
This works:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ReloadComboBox;
  2. begin
  3.   DBComboBox1.Clear;
  4.   ZQ2.Close;
  5.   ZQ2.SQL.Text := 'SELECT name FROM pupils';
  6.   ZQ2.Open;
  7.   ZQ2.First;
  8.   while not ZQ2.EOF do
  9.   begin
  10.       DBComboBox1.Items.Add(ZQ2.FieldByName('name').AsString);  // changed .DisplayText to .AsString
  11.     ZQ2.Next;
  12.   end;
  13.   DBComboBox1.Sorted := True;
  14. end;

Thanks for your input, Zvoni.  It pushed me in the right direction.
Linux Mint 21.3
Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2329
Re: [SOLVED] (MEMO)s in my TDBComboBox
« Reply #6 on: June 17, 2022, 02:01:28 pm »
Just saw it: You'll have to explain why you use a TDBComboBox, which is a Data-aware Control, when you're manually filling it up.
That's why i stumbled with the SQL
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: [SOLVED] (MEMO)s in my TDBComboBox
« Reply #7 on: June 17, 2022, 02:17:10 pm »
Already ahead of you.  I changed that to a regular TComboBox after I ran a few checks on the DBComboBox. 

When I first added that DBComboBox and hard-wired the SQL string of the ZEOS Query component, it just loaded one (MEMO).  So I added the Reload procedure, and that did add all the table rows.  But all were (MEMO).  That brought me here, to the forum.  And right after posting the above, I saw that I cldn't select anything from the DBComboBox.  A TComboBox solved that. 

« Last Edit: June 17, 2022, 04:52:22 pm by Slyde »
Linux Mint 21.3
Lazarus 3.0

 

TinyPortal © 2005-2018