Recent

Author Topic: [SOLVED] Dbl-Click Listbox Value not working for me  (Read 432 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
[SOLVED] Dbl-Click Listbox Value not working for me
« on: May 19, 2019, 01:19:39 am »
I have this issue I can't seem to figure out what is going on.

I have a listbox on a form filled with "Items" list

When you just click on an item in the list I can send the value to a label, I can also show the value in a MSGbox

But, If I double-click on it and try to evaluate the value using IF ELSE, it returns nothing.

According to WIKi and other docs the list box returns a string list.
And since I am getting the string from the list item, WHY is this happening?

CODE:

Code: Pascal  [Select]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     lbCMD: TLabel;
  18.     lstCMD: TListBox;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure lstCMDClick(Sender: TObject);
  21.     procedure lstCMDDblClick(Sender: TObject);
  22.   private
  23.  
  24.   public
  25.  
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32. {$R *.lfm}
  33. { TForm1 }
  34.  
  35. procedure TForm1.lstCMDClick(Sender: TObject);
  36. begin
  37.     lbCMD.Caption:=lstCMD.Items[lstCMD.ItemIndex];
  38. end;
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. begin
  42.   showmessage(lstCMD.Items[lstCMD.ItemIndex]);
  43. end;
  44.  
  45. procedure TForm1.lstCMDDblClick(Sender: TObject);
  46. begin
  47.   if lstCMD.Items[lstCMD.ItemIndex] = 'assoc' Then
  48.        showmessage('yes')
  49.     else
  50.        showmessage('no');
  51. end;
  52. end.
  53.  
  54.  

DEMO PROJECT (that doesn't work)
« Last Edit: May 19, 2019, 01:46:22 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

ASerge

  • Hero Member
  • *****
  • Posts: 1390
Re: Dbl-Click Listbox Value not working for me
« Reply #1 on: May 19, 2019, 01:30:11 am »
In unit1.pas 'assoc', int unit1.lfm 'assoc'#9.  It's not the same thing.

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: Dbl-Click Listbox Value not working for me
« Reply #2 on: May 19, 2019, 01:33:05 am »
In unit1.pas 'assoc', int unit1.lfm 'assoc'#9.  It's not the same thing.

What?... What do you mean... this is as basic as a project can be, didn't change anything.
"assoc" is a word in the list box, not a command or anything.

So, i am not sure what you are saying.
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: Dbl-Click Listbox Value not working for me
« Reply #3 on: May 19, 2019, 01:35:31 am »
Also, in the demo change the word "assoc" to anything else in the list... does the same thing... returns "no" in msgbox (no match)
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

ASerge

  • Hero Member
  • *****
  • Posts: 1390
Re: Dbl-Click Listbox Value not working for me
« Reply #4 on: May 19, 2019, 01:42:32 am »
What?... What do you mean... this is as basic as a project can be, didn't change anything.
"assoc" is a word in the list box, not a command or anything.
What is there to understand: 'assoc' <> 'assoc'#9.

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: Dbl-Click Listbox Value not working for me
« Reply #5 on: May 19, 2019, 01:42:51 am »
Okay... I figured out what you are trying to say.

I went in and double checked the string list and there ere spaces at the end of some of the strings.

Remove, and it WORKS!!!

THANK YOU!
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: Dbl-Click Listbox Value not working for me
« Reply #6 on: May 19, 2019, 01:45:05 am »
What?... What do you mean... this is as basic as a project can be, didn't change anything.
"assoc" is a word in the list box, not a command or anything.
What is there to understand: 'assoc' <> 'assoc'#9.

Crossed posts... because I didn't know what you were referring to with #9, I was looking at line numbers, didn't realize that it is a space.

I am a newbie... don't talk cryptic code... just say... you have spaces at the end of your string.
That is easier to understand.

Anyways... its working now, THANKS!
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

lucamar

  • Hero Member
  • *****
  • Posts: 1982
Re: Dbl-Click Listbox Value not working for me
« Reply #7 on: May 19, 2019, 02:14:02 am »
[...] because I didn't know what you were referring to with #9, I was looking at line numbers, didn't realize that it is a space.

Not really a space, but a TAB character. You tapped the TAB key after writing "assoc".
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.