Recent

Author Topic: Which Control should I use ?  (Read 2012 times)

440bx

  • Hero Member
  • *****
  • Posts: 6559
Re: Which Control should I use ?
« Reply #15 on: June 13, 2026, 08:04:18 pm »
I must be missing something...

Code: Pascal  [Select][+][-]
  1.   If Font_Style.Checked[0] := true then I := 0
  2.  
does FPC now allow an assignment in an if statement ?  shouldn't that line be "= true" and not ":= true" ?

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #16 on: June 13, 2026, 08:37:33 pm »
I must be missing something...

Code: Pascal  [Select][+][-]
  1.   If Font_Style.Checked[0] := true then I := 0
  2.  
does FPC now allow an assignment in an if statement ?  shouldn't that line be "= true" and not ":= true" ?

No you are not 'missing something' AFAIK  ::)  -  that was an early attempt that didn't compile!
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #17 on: June 13, 2026, 09:03:51 pm »
Hi
Ok, after setting 'AutoSelect' to false, you could try to focus another widget, say a button, maybe... %)
Regards Benny

I've tried that @Benny but even though the [Focus] does move to the selected component - which does become highlighted - the Font Name is still highlighted as well  ?????  Witness the attached Screen Grab.

I've even thought about creating a [Button] at a size of 1 x 1 pixel but since the highlighting is not broken by a confirmed change of focus I don't see how even that would help.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 13630
Re: Which Control should I use ?
« Reply #18 on: June 13, 2026, 09:36:00 pm »
To make sure that I understand correctly: Your concern is that the text in the combobox is drawn as being "highlighted" (with blue background)? And when you select another control on the form, that highlight does not go away?

This behaviour is absolutely not normal. I created a new project with an empty form, added a ComboBox with some dummy items, as well as a few Edit controls. When I run this there is only one control to display the highlighted background.

I think the issue must be somewhere in your code. Strip everything not needed from your project and post it here.

440bx

  • Hero Member
  • *****
  • Posts: 6559
Re: Which Control should I use ?
« Reply #19 on: June 13, 2026, 11:04:58 pm »
No you are not 'missing something' AFAIK  ::)  -  that was an early attempt that didn't compile!
Thank you J-G.  You mentioned the compiler had emitted an error for a different line which made me think that maybe it had accepted that line, I thought I should have confirmation of that.

Thanks again.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #20 on: June 13, 2026, 11:52:29 pm »
To make sure that I understand correctly: Your concern is that the text in the combobox is drawn as being "highlighted" (with blue background)? And when you select another control on the form, that highlight does not go away?

This behaviour is absolutely not normal. I created a new project with an empty form, added a ComboBox with some dummy items, as well as a few Edit controls. When I run this there is only one control to display the highlighted background.

I think the issue must be somewhere in your code. Strip everything not needed from your project and post it here.

I'm at least reassured by your statement @WP  -  absolutely not normal -  In your program I find that the 'Highlighting' of the TComboBox happens with a single mouse click but the [Edits] need a double mouse click. (Just an observation)

My programs all use a Unit I created some while ago to deal with Time & Date (JGDT) so I tried to comment out the parts that needed that but got into a serious problem that meant that it didn't compile. I had to resort to recovering a backup :( 

I have [Published] the program and attach the .ZIP file - what I don't know is whether that will automatically include the JGDT unit. If you need it as a separate 'publish' I'm happy to do that as well.

There are two DATA files - very small so I've added those to the .ZIP file. They would be created at startup of course but having them will make life a little easier I suspect.

Now that I've opened the .ZIP file, I see that JGDT is NOT included -  so I've manually added the JGDT.exe file as well. If you need the .pas/.lpi ... etc. I could attach them to a further post.

Thanks for your interest and let's hope that you see the same effect that I do - and can find a reason for such :)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 13630
Re: Which Control should I use ?
« Reply #21 on: June 14, 2026, 12:52:12 am »
I had to remove a lot of unnecessary things before I could compile the project. Then it took me some time to find out how to get the panel you are talking of: I had to click on the small "Margins/Tabs/Font" box in the lower right corner.

Yes, I can reproduce the issue whenever I click on "Bold" or "Italic" the text in the combobox is drawn as highlighted, and this is persistent, because when I then double-click on one of the Edit fields that is highlighted as well (because it is focused) but the highlighting background of the combobox remains.

There's nothing special with the Bold/Italic comboboxes and the combobox, and even when I undo the property changes that you made to the combobox nothing improves. --- Strange...

I added two checkboxes to my former test project and coded them such that they set the combobox font to bold or italic, just like you - and this shows the same effect.

Therefore, I think that this is clearly a bug, at least in the Windows widgetset, since it does not occur on macOS which I tested as well.
« Last Edit: June 14, 2026, 01:29:28 am by wp »

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Which Control should I use ?
« Reply #22 on: June 14, 2026, 01:20:35 am »
<snip>
Is there some other method by which I can present a 'clean' panel display ?   ie. NO highlighting.
<snip>
Please have a look at the attached ZIP file and screenshot.

In the Project Inspector, check the cmbFontName combobox. You'll notice that AutoSelect is checked. In the code, this property is disabled at line 65.

This may help resolve the issue you're seeing, although it may not be exactly what you're looking for. It may help or at least provide a clue as to what's causing the behaviour you're seeing. Hopefully it points you in the right direction.

At the very least, it should provide a useful starting point for further investigation.

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #23 on: June 14, 2026, 01:35:13 am »
I had to remove a lot of unnecessary things before I could compile the project. Then it took me some time to find out how to get the panel you are talking of: I had to click on the small "Margins/Tabs/Font" box in the lower right corner.

Yes, I can reproduce the issue whenever I click on "Bold" or "Italic" the text in the combobox is drawn as highlighted, and this is persistent, because when I then double-click on one of the Edit fields that is highlighted as well (because it is focused) but the highlighting background of the combobox remains.

There's nothing special with the Bold/Italic comboboxes and the combobox, and even when I undo the property changes that you made to the combobox nothing improves. --- Strange...

I added two checkboxes to my former test project and coded them such that they set the combobox font to bold or italic, just like you - and this shows the same effect.

Therefore, I think that this is clearly a bug, at least in the Windows widgetset only, since it does not occur on macOS which I tested as well.

Apologies @WP  -  I had meant to tell you that the [Panel] was normally hidden and to click on the MTF button but with all the probems I created for myself I slipped my mind. Getting into someone elses mindset can be quite a challenge !

At least again I am heartened by the fact that you could re-produce the effect and can agree that it's not something that I might have caused by my code.  It is a strange effect - essentially indicating that two separate components are 'Focused'.  It's a minor point, which I can live with -  it's not as if my program is going to be used by anyone of note (likely just my grandson and a friend/colleague of his) and there is little to no chance that there will be any interest in correcting whatever unit/widgit set that I'm using (since I'm still on FPC 3.2.2 and Laz 2.2.0  :o )

Regrettably, although I can 'download' your Mini-project - when un-zipped it shows the same 'Empty' Object inspector that your first offering did - obviously the same 'Compatability' flag needs setting :)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #24 on: June 14, 2026, 01:55:19 am »
<snip>
Is there some other method by which I can present a 'clean' panel display ?   ie. NO highlighting.
<snip>
Please have a look at the attached ZIP file and screenshot.

In the Project Inspector, check the cmbFontName combobox. You'll notice that AutoSelect is checked. In the code, this property is disabled at line 65.

This may help resolve the issue you're seeing, although it may not be exactly what you're looking for. It may help or at least provide a clue as to what's causing the behaviour you're seeing. Hopefully it points you in the right direction.

At the very least, it should provide a useful starting point for further investigation.

The display shown by your project shows EXACTLY the same problem -  ie. the Font Name in the TComboBox has the blue background - even when the focus is on any of the SpinEdits.

It has, however, given me food for thought about the best way to show the Paper Size & Margins.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Aruna

  • Hero Member
  • *****
  • Posts: 814
Re: Which Control should I use ?
« Reply #25 on: June 14, 2026, 03:15:12 am »
<snip>
Is there some other method by which I can present a 'clean' panel display ?   ie. NO highlighting.
<snip>
Please have a look at the attached ZIP file and screenshot.

In the Project Inspector, check the cmbFontName combobox. You'll notice that AutoSelect is checked. In the code, this property is disabled at line 65.

This may help resolve the issue you're seeing, although it may not be exactly what you're looking for. It may help or at least provide a clue as to what's causing the behaviour you're seeing. Hopefully it points you in the right direction.

At the very least, it should provide a useful starting point for further investigation.

The display shown by your project shows EXACTLY the same problem -  ie. the Font Name in the TComboBox has the blue background - even when the focus is on any of the SpinEdits.

It has, however, given me food for thought about the best way to show the Paper Size & Margins.
The only thing I could think of to resolve your issue was to draw everything using 'ownerdraw'. When you run the application you will see two cmboboxes. The top one has the problem your experiencing and the bottom one has it resolved. Hope this will help. The zip has minimal code so will be easy to understand.

@wp, @dsiders, @Martin_fr in case even this fails am thinking might be a good idea to upgrade to a 4.8? We can always show the op how to have multiple installations peacefully co-existing side by side with --pcp ?


paweld

  • Hero Member
  • *****
  • Posts: 1685
Re: Which Control should I use ?
« Reply #26 on: June 14, 2026, 05:29:26 am »
@J-G:
Code: Pascal  [Select][+][-]
  1. procedure Set_DefaultFont_Display;
  2. begin
  3.   with TriangleSolution do
  4.    begin
  5.      FontNames.ItemIndex   :=prDefFont.Name;
  6.      FontNames.Font.Style  :=prDefFont.Style;
  7.      FontNames.Font.Size   :=prDefFont.Size;
  8.      FntSz.Caption         :=IntToStr(prDefFont.Size);
  9.      if FontNames.Font.Style = [fsBold] then
  10.        Bold_Tic.Checked    :=True;
  11.      if FontNames.Font.Style = [fsItalic] then
  12.        Italic_Tic.Checked  :=True;
  13.      FontNames.SelLength := 0;  //clear selection
  14.      LM_EditEditingDone(nil);  //refresh margins visualisation begin
  15.      RM_EditEditingDone(nil);  //..
  16.      TM_EditEditingDone(nil);  //..
  17.      BM_EditEditingDone(nil);  //refresh margins visualisation end
  18. //     FontNames.Focused := false;
  19.    end;
  20.  
  21. end;    
Best regards / Pozdrawiam
paweld

jamie

  • Hero Member
  • *****
  • Posts: 7852
Re: Which Control should I use ?
« Reply #27 on: June 14, 2026, 12:05:43 pm »
I guess i am late to the party.

SPIN edits do not take focus, they are TgraphicControl.

There for the behavior is expected and benifits to where u can use such controls without losing the focus of a window control.

P.s.
  The TUpDown control is a windows type, i believe you can make that work if you looking for a spin type effect.
 Jamie
« Last Edit: June 14, 2026, 12:11:21 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 13630
Re: Which Control should I use ?
« Reply #28 on: June 14, 2026, 12:38:10 pm »
Regrettably, although I can 'download' your Mini-project - when un-zipped it shows the same 'Empty' Object inspector that your first offering did - obviously the same 'Compatability' flag needs setting :)
I am absolutely sure that I had set the checkbox in the project settings. Why is it gone now? Mysterious...

Anyway, I now also tested on Linux the gtk2, gtk3, qt5 and qt6 widgetsets, and they do not show the issue. It is clearly a windows-only bug then.

I am attaching a new version of my mini project which (hopefully...) should work. It contains two more, currently commented-out, lines which allow you to workaround it issue: Set Combobox1.SelLength := 0 after changing the font, and the selection highlight will be gone...

J-G

  • Hero Member
  • *****
  • Posts: 1114
Re: Which Control should I use ?
« Reply #29 on: June 14, 2026, 05:39:17 pm »
Where has the day gone ???

I've had a great deal of information/suggestions to process today, thanks to you all and I've been down a veritable Rabbit Warren finding all manor of issues that I'd missed in my quest to make the page setup as flexible as possible for the user.

The upshot is that I now do have an MTF Panel which works as required (mostly)  -  there is still a small matter of the font name retaining the blue background but only when it has been modified (Name, Size or Style)  which to be fair is not unreasonable.

The important issue of it being [clean] on initial display is solved - thanks to the code snippet provided by @paweld  -  no instruction, just code that I could copy & paste  ;D.  It took me a while to see what was suggested (and I still don't understand what the code really does!) but @WP sort of confirmed that at least one line of that code may well be effective - FontNames.SelLength := 0;  and I've just realised what that is doing !!!  -  it's saying the 'length of the selected part of the string is ZERO'  - it may be a 'fudge' but it certainly does the job.

I'd be grateful for a little explanation regarding the other 4 lines of @paweld's code : LM_EditEditingDone(nil); et. al.  -  to me it seems that they are calling my Margin Editing procs with a (Nil) argument. I haven't yet tried to compile without those lines in place but I suspect that they may be superfluous.

The attached Screen Grab shows the current MTF Panel display when first called (mouse click on MTF button).

Having gained some further understanding of FontNames.SelLength := 0;  I've just re-compiled after adding that to the FontNamesChange Event  - but it doesn't clear the blue background  :(  No matter.

@Aruna's suggestion of 'OwnerDraw' will need much further study - I have run the demo (and added [Bold] & [Italic] checkboxes)  so can confirm that there is a difference, but I just don't yet have enough knowledge to impliment such a change.

One good thing to come out of this excercise is that I've re-written a lot of the MTF Panel code such that the position of the page display and the location of the TEdits is now 'Relative' rather than 'Absolute'. I'd previously hard coded the Top/Left/Width/Height of them but - because the user could select Portrate or Landscape - they are now set relative to the position of the TShape which is the page image (it was initially a TLabel so didn't have an outline). The 'margins' image now has to be changed to a TShape as well (currently a TImage with a dashed line rectangle drawn on it).

I must further express my gratitude to all contributors - I've had a great day of learning, hopefully some of that knowledge will have stuck !  ::)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018