Recent

Author Topic: Implicit transfer of control to a frame  (Read 334 times)

dgrhoads

  • New member
  • *
  • Posts: 8
Implicit transfer of control to a frame
« on: May 24, 2020, 04:11:23 am »
I have two sets of complex computations which once started do not require user input.  It would be nice to have each set in a separate frame.  The process would be to have all input come from a form and then transfer control to the frame for the calculation. However, my experiments indicate that there is no automatic mechanism to start any calculations in the frame. 

The only way calculations start is if I click on a button on the form.  The button doesn't have to be connected to anything.  Once I press the button, then code in MyFrame.FrameShow starts to run.

In other words, it seems that even though the frame is displayed on the form, there is no way to transfer focus to that frame without having to click on something in the form.  Is that true?

jamie

  • Hero Member
  • *****
  • Posts: 2936
Re: Implicit transfer of control to a frame
« Reply #1 on: May 24, 2020, 12:32:31 pm »
So I assume your code is within a OnClick button event ?

You can directly execute the event if you wish....

Code: Pascal  [Select][+][-]
  1. if Assigned(Button1.OnClick) Then button1.OnClick(Self);
  2.  

and to move focus...
Code: Pascal  [Select][+][-]
  1. button1.SetFocus;
  2.  

Is that it ?
Number 1 at blue screen app creations!

lucamar

  • Hero Member
  • *****
  • Posts: 2856
Re: Implicit transfer of control to a frame
« Reply #2 on: May 24, 2020, 12:34:37 pm »
Frames can't adquire focus, only the controls inside them. And frankly, I can't undertand why you need a frame for what you're apparently doing; wouldn't it be better (if you wnat to keep it separate) to implement your calculations in a normal unit? What are you exactly doing and why do you use a frame for it?

If it's a question of "complex calculations" freezing your form, wouldn't it be better doing them in a thread?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 2936
Re: Implicit transfer of control to a frame
« Reply #3 on: May 24, 2020, 02:17:27 pm »
Its possible a Thread is started but if that is the case then with that knowledge base this question should of never appeared ?

Number 1 at blue screen app creations!

dgrhoads

  • New member
  • *
  • Posts: 8
Re: Implicit transfer of control to a frame
« Reply #4 on: May 24, 2020, 09:26:43 pm »
To Jamie:  Your comment is in line with my observations.  One key concept that I am learning is that frames are designed specifically for those situations in which there will be user interaction with the program.

I do retrieve data from my DB into tables which I use in my application.  The architecture that you suggest I use, would be to put the calculations into a unit with a non-visual form.  Is that the direction that you feel I should go?

Thanks for your comments.  Sometimes I need all the help I can get.

jamie

  • Hero Member
  • *****
  • Posts: 2936
Re: Implicit transfer of control to a frame
« Reply #5 on: May 25, 2020, 03:18:52 am »
you can do that

 what I meant was if you implement a OnClick handler event with one of the buttons you don't need user action to execute any of the code that is within that event method, you can call it directly if you wish..

 Just double click the button on the form and a new method block will start for you. You can put all of that code you need to calculate in that even or in a separate unit.
 
 And a code call would be to directly execute that event instead of waiting for the user to do it..

 It depends if this code is designed to work either way.. If its not designed to work with a user trigger then create a Procedure in your main body of code and simply call it..
Or have it in another unit if you wish.
 
 But I take it that it could be this code fragment maybe time consuming and you wish for it to process in the background while doing other stuff, is this it ?
Number 1 at blue screen app creations!

 

TinyPortal © 2005-2018