Recent

Author Topic: [Solved] Setting form focus  (Read 4420 times)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Setting form focus
« on: July 29, 2024, 11:04:19 pm »
i am keeping track of which form are being shown on my screen. I use the following array to keep track of them
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyForms  = record
  3.                 Index: Integer;
  4.                 Naam: string;
  5.               end;  // TMyForms
  6.  
  7.  
  8. var MyForms: Array [0..9] of TMyForms;


How can i now set the form that is stored in my MyForms when the index is lets say 2.
« Last Edit: July 31, 2024, 10:49:01 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

jamie

  • Hero Member
  • *****
  • Posts: 7855
Re: Setting form focus
« Reply #1 on: July 29, 2024, 11:05:38 pm »
SetFocus ?
The only true wisdom is knowing you know nothing

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #2 on: July 29, 2024, 11:06:51 pm »
can't get  that to work


Is there a way to set the focus of a named form instead of using the index?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Setting form focus
« Reply #3 on: July 29, 2024, 11:09:56 pm »
i am keeping track of which form are being shown on my screen. I use the following array to keep track of them
...
How can i now set the form that is stored in my MyForms when the index is lets say 2.
What does that mean, set the form ? If you do not know the correct terminology then try to describe what it is that you want to happen for that say form 2.
Today is tomorrow's yesterday.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #4 on: July 29, 2024, 11:16:42 pm »
Oke let's try that again


the steps i am taking to open several forms.
open forrm 1
store in MyForms as [0, 'Form1']


Open form 2
Store in MyForm as [1, 'Form2']


Open form 3
Sore in MyForm as [2, 'Form3']


do some stuff on form 3 and then use a question form [Just a simple yes or no] to close form 3


Now i want to set the active form to form 2.
HOW DO I DO THAT?


Code: Pascal  [Select][+][-]
  1.   Screen.Forms[LintIndex].SetFocus;
  2.  
does not work


Also read this https://forum.lazarus.freepascal.org/index.php/topic,68046.0.html
« Last Edit: July 29, 2024, 11:21:51 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Handoko

  • Hero Member
  • *****
  • Posts: 5558
  • My goal: build my own game engine using Lazarus
Re: Setting form focus
« Reply #5 on: July 30, 2024, 05:49:25 am »
I can think of 2 possibilities, which one do you want?

For example, this is already in the array:
[0, 'Form1']
[1, 'Form2']
[2, 'Form3']
[4, 'Form4']


User does not close Form4 but clicks the Form2. Which result do you want?

Result1:
[0, 'Form1']
[1, 'Form2']
[2, 'Form3']
[4, 'Form4']
[5, 'Form2']

Result2:
[0, 'Form1']
[1, 'Form3']
[2, 'Form4']
[3, 'Form2']


I saw you're not using dynamic array, so my guess you want Result2. I am not saying Result1 is better, each one has its own advantages, disadvantages and its use case. Is it correct, Result2 is what you want? Or maybe something else?

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #6 on: July 30, 2024, 09:28:29 am »
Indeed result 2
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Setting form focus
« Reply #7 on: July 30, 2024, 09:39:43 am »
Indeed result 2
What do you mean by 'Open form'? Form.Show? Are your forms auto-created or you create them explicitly?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #8 on: July 30, 2024, 09:48:23 am »
It doesn't matter how the forms are created.
The forms are open and on the screen.
I just need to get them refocused in the right order.
And THAT is my problem.


Everytime you do a xxx.Show the order that lazarus uses is the WRONG order for my app
« Last Edit: July 30, 2024, 10:02:52 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #9 on: July 30, 2024, 10:06:09 am »
Ideally you would open a form (1) and when you open another form (2) the other form (1) becomes inaccessible.


But unfortunately lazarus does not work that way so I have to find a work around and that is what this is all about
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Setting form focus
« Reply #10 on: July 30, 2024, 10:17:56 am »
Ideally you would open a form (1) and when you open another form (2) the other form (1) becomes inaccessible.
Form2.ShowModal?
« Last Edit: July 30, 2024, 10:19:47 am by alpine »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

cdbc

  • Hero Member
  • *****
  • Posts: 2874
    • http://www.cdbc.dk
Re: Setting form focus
« Reply #11 on: July 30, 2024, 10:23:27 am »
Hi
How about keeping your forms(references) in some sort of list, instead of an array, that way, when the user selects a form, you can utilize the 'Move' method of said list, to relocate the form-ref to the last element in the list.
When it's 'quit'in' time, you just do
Code: Pascal  [Select][+][-]
  1. for i:= aList.Count-1 downto 0 do aList[i].Free;
So, during runtime it acts like a list(with stack-like properties) i.e.: doesn't remove when selected. And by freeing, it acts purely like a stack, popping of the latest...
Regards Benny
edit: added code-tags... Sorry.
« Last Edit: July 30, 2024, 10:32:30 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #12 on: July 30, 2024, 10:27:44 am »
That's the whole thought of the array :)
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

cdbc

  • Hero Member
  • *****
  • Posts: 2874
    • http://www.cdbc.dk
Re: Setting form focus
« Reply #13 on: July 30, 2024, 10:34:21 am »
Hi
Using a list, you get the (well tested) 'Move' implementation for free  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Setting form focus
« Reply #14 on: July 30, 2024, 10:41:10 am »
i am keeping track of which form are being shown on my screen. I use the following array to keep track of them
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyForms  = record
  3.                 Index: Integer;
  4.                 Naam: string;
  5.               end;  // TMyForms
  6.  
  7.  
  8. var MyForms: Array [0..9] of TMyForms;
I think we all agree here that the method is ok.

But now the hard part making it work
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018