Recent

Author Topic: [SOLVED] FileListBox losing focus  (Read 880 times)

Jumbo

  • New Member
  • *
  • Posts: 29
[SOLVED] FileListBox losing focus
« on: August 04, 2022, 06:34:38 pm »
This is about a program I used for some years and wrote it myself.

In short, a form with a filelistbox, the entries are clickable. When selected an entry, a second form draws a figure.

In the past, not sure about when I used it last time, I could select an entry in the list and put my finger on the up or down key
and then the list was scrolled up or down and each entry would "OnChange" draw a figure.
Very funny to see all the figures flashing by...
( The figures are airfoil profiles if it matters to you , drawn from a coordinate list )

This ran for a long time fine, on linux mint.

But now the background pops up between the selections and the focus is lost.

So now the every 2 or 10 "changes" in the list the focus is lost and I need to click on some entry to start scolling again.

For some reason I think linux mint is causing the problem but I cannot be sure about it.
Does someone recognise this behaivior ?
« Last Edit: August 11, 2022, 11:24:27 am by Jumbo »

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: FileListBox losing focus
« Reply #1 on: August 04, 2022, 07:17:57 pm »
The chances, I have it, are small. The effort to try is low.
I came from Delphi under Window and to my old projects new as well.
Give it a try to change "scroll width".



balazsszekely

  • Guest
Re: FileListBox losing focus
« Reply #2 on: August 04, 2022, 07:32:06 pm »
@Jumbo

If I understood you correctly, you do the drawing on the FileListBox OnChange event and sometimes the focus is lost for some reason? I cannot reproduce this issue at my side, however you can try the following:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FileListBox1Change(Sender: TObject);
  2. begin
  3.   //drawing to the second form
  4.   //...
  5.   Self.BringToFront;
  6.   TFileListBox(Sender).SetFocus;
  7. end;  
It would be nice to know why the focus is lost though.

Jumbo

  • New Member
  • *
  • Posts: 29
Re: FileListBox losing focus
« Reply #3 on: August 04, 2022, 08:01:59 pm »
Thanks for the quick response.

I made a seperate procedure for setfocus:

procedure TForm1.setFocus(Sender: TObject);
begin
  Self.BringToFront;
  TFileListBox(Sender).SetFocus;
  FileListBox1.SetFocus;
end; 

It works ! But the result is a very flashing listbox-form...
Every new selection the whole Form is repainted.
Say a 100 entries, then a 99 repaints.
I am pretty sure it did not work this way before.

<ot>
Could it be a collision between Lazarus/pascal and linux-mint/xfce at the other hand?

I have an issue with firefox/youtube-video an the zoom funktion in xfce.
When zooming, the video becomes flashing and then disappears.

From the mint-guys I get no answer to this question.

But from the outside, the behaivier look the same as for the pascal-form
</ot>
« Last Edit: August 04, 2022, 08:05:45 pm by Jumbo »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: FileListBox losing focus
« Reply #4 on: August 04, 2022, 08:15:21 pm »
Alright, maby I was quick to react. But it fails still but less then without the focus procedure.
Can even have them displayed all without a lost focus.

What My eye got in de console/devellop env. 

This message: NOTE: Window with stalled focus found!, faking focus-out event.

Maybe that does tell someone something ?

Btw: If not a separate procedure does not make a difference:

procedure TForm1.FileListBox1Change(Sender: TObject);
var
  myFile: String;
begin
  myFile := FileListBox1.FileName;
  Form2.myFile := myFile;
  Form2.Show;
  Form2.setTitle(myFile);
  Form2.showFoil();
  //Form1.SetFocus(Sender);
  Self.BringToFront;
  TFileListBox(Sender).SetFocus;
  FileListBox1.SetFocus;
end;   
« Last Edit: August 04, 2022, 08:18:42 pm by Jumbo »

balazsszekely

  • Guest
Re: FileListBox losing focus
« Reply #5 on: August 04, 2022, 08:27:17 pm »
Quote
Alright, maby I was quick to react. But it fails still but less then without the focus procedure.
Can even have them displayed all without a lost focus.

What My eye got in de console/devellop env.

This message: NOTE: Window with stalled focus found!, faking focus-out event.

Maybe that does tell someone something ?

Btw: If not a separate procedure does not make a difference:
Why do you call  Form2.Show each time?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FileListBox1Change(Sender: TObject);
  2. var
  3.   myFile: String;
  4. begin
  5.   myFile := FileListBox1.FileName;
  6.   Form2.myFile := myFile;
  7.   if not Form2.Visible then
  8.   begin
  9.     Form2.Show;
  10.     Form1.BringToFront;
  11.     FileListBox1.SetFocus;
  12.   end;
  13.   Form2.setTitle(myFile);
  14.   Form2.showFoil();
  15. end;  

PS: I assume Form2.setTitle and Form2.showFoil() don't steal focus.

Jumbo

  • New Member
  • *
  • Posts: 29
Re: FileListBox losing focus
« Reply #6 on: August 04, 2022, 09:00:45 pm »
Hm, you are right. Changed that to check first.

Strange behaivior remains...

UPDATE:  the message : "NOTE: Window with stalled focus found!, faking focus-out event."  is gone for whatever reason.
« Last Edit: August 04, 2022, 09:10:44 pm by Jumbo »

Jumbo

  • New Member
  • *
  • Posts: 29
Re: FileListBox losing focus
« Reply #7 on: August 11, 2022, 11:23:53 am »
Sorry to all of you. Just now my eyes fell on the error.

When I started form2, i did a hide of form1.  Realy no idea why.  But even more I don´t know why it ever worked fine.

Anyway, I changed it a bit, Form No longer forced to hide, and focus is not lost.
Only issue, focus is lost at first plot in form2. But solved also.

In form1 :

procedure TForm1.setMyFocus();
begin
  Self.BringToFront;
  FileListBox1.SetFocus;
end;

In form2 :

procedure TForm2.showFoil();
begin
  //Form1.hide;
  getCoords();
  convertCoords();
  plotFoil();
  Form1.SetMyFocus();
end;

This is now working fine. Focus is no longer lost from the file-list-box and scrolling works fine.

 

TinyPortal © 2005-2018