-2

Is there a way to make it so you don't have to double up your &'s to make Delphi list box not register them as hotkeys?

We've got a list of drug names that we populate in a ListBox, some of the drugs have &'s in them like "A & D Ointment", well it's kind of dumb to have "A _D Ointment" show up so we double up the &&'s to make it "A & D Ointment" the only problem is, when we do that we can't us the text in the list box for anything useful without re-unconverting the text.

It would be must more convenient for us to just turn off the hotkey thing altogether which I can't seem to find a way to do with the IDE, but I'm sure there's some fancy windows message to override this (hopefully I don't have to override the base class)


We're overriding the DrawItem function using:

DrawText(List.Canvas.Handle, PChar(List.Items.Strings[Index]), -1, Rect, DT_VCENTER);
Peter Turner
  • 11,199
  • 10
  • 68
  • 109
  • 3
    This simply doesn't happen. Are you sure you are actually dealing with a `TListBox`? – Andreas Rejbrand Sep 03 '14 at 15:22
  • Agree with @Andreas; e.g. in Delphi 7 or Delphi XE3, the `TListBox` item text is rendered explicitly with the [`DT_NOPREFIX`](http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx#DT_NOPREFIX) flag included (which prevents from rendering underscores from `&` chars). – TLama Sep 03 '14 at 15:28
  • @AndreasRejbrand ohhhh dumb, the guy who wrote the code is drawing it manually... – Peter Turner Sep 03 '14 at 15:29
  • @TLama OK thanks fellas, I'm going to let someone in the office answer this question. I was going to delete it the question, but he thought it might be useful to someone. – Peter Turner Sep 03 '14 at 15:33
  • @jerry I thought it was a list view when I wrote it originally, but I went back to the code and realized it wasn't. Why on earth did your question get so many -1's? And furthermore, how is this a duplicate when only the answer is the same. It really seemed to us three experience delphi programmers, that it was the control doing something to the text we passed in automatically and it's impossible to make a mental leap between double ampersands, hotkeys and DT_NOPREFIX. I don't know what sort of a point you're trying to prove but you're dead wrong by closing this. – Peter Turner Sep 03 '14 at 17:50
  • @Peter I didn't close this myself, I was just one of many others who voted. And questions don't have to be worded the same to be duplicate. We're both asking the same thing essentially: "How to get rid of ampersand underscore handling?" – Jerry Dodge Sep 03 '14 at 17:56
  • @Peter The control doesn't do anything because the control doesn't paint the text. The discussion of list boxes is not relevant because the list box isn't painting. It's just the DrawTrext that counts. – David Heffernan Sep 04 '14 at 06:32

1 Answers1

3

You're probably not using the default TListBox draw function if this is happening as by default it uses DT_NOPREFIX to draw things.

Check and make sure you're not overriding the DrawItem function to see if use DrawText without DT_NOPREFIX. If you use DT_NOPREFIX, then your text will remain the same.

Peter Turner
  • 11,199
  • 10
  • 68
  • 109
Darin Ballweg
  • 188
  • 1
  • 11
  • 1
    -1 As asked, `DrawText` is not relevant. List boxes don't do what is described in the question. Perhaps if you want to edit the question to describe a scenario to which this answer applies, then it might be useful to somebody in the future. But as it stands this is very misleading. – David Heffernan Sep 03 '14 at 15:43
  • OK, downvote removed. It would be far far better if you removed all talk about list boxes and just included the call to `DrawText`. – David Heffernan Sep 03 '14 at 15:54
  • This problem is a combination of `DrawText` DT flag and the fact that the list box was on the manual draw. In this sense it might be helpful to somebody. – serge Sep 03 '14 at 15:58
  • 2
    Helpful to the people in your company, yes. Helpful to future users of Stack Overflow, no. Stack Overflow isn't a place for your company to document your code. – Jerry Dodge Sep 03 '14 at 16:03
  • 2
    This can't be helpful to future visitors until the question is fixed. – David Heffernan Sep 03 '14 at 17:10