Recent

Author Topic: [Solved]TPageControl  (Read 2163 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
[Solved]TPageControl
« on: February 14, 2018, 12:15:02 am »
Hi

 i have many TPageControl in my project.
 
 i write some codes in the  "PageChange" event.
 
 in body of my project , i use this code :
 
 PageControl1.activepageindex := 2
 
 with this code , i chage page index and also run codes of "PageChange" event.
 
 when i install lazarus 1.8 (that i wish didn't do this)
 
 i just open my project and run it .
 
 when i use :
 
 PageControl1.activepageindex := 2

only page of pagecontrol change and code of "PageChange" event doesn't run.

why???

please run this project in Lazarus1.6  and Lazarus 1.8 and see this different

and guide me.

Thank you
« Last Edit: February 16, 2018, 11:07:17 am by majid.ebru »

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TPageControl
« Reply #1 on: February 14, 2018, 12:38:13 am »
Many events with controls that involves interaction with the USER should only fire (trigger) when the
user CLICKS on a tab, for example.
 
 Because you do this in your code, you should be calling the event directly if that is what you
wish to happen..

 So when changing a state in a control via code and that same event can also get called when the
user interacts with the control, should be isolated.

 Create a stand alone Procedure that will need to be called if your code or the USER changes the tab
index.


-- For USER actions (Click) ___
 OnChange(....)
   Begin
      Call_Basic_PRocedure;
      // do other code that reflects user ACTION only here..
   End;

-- For your code to make changes ---
   PageControl.ActuvePageIndex := 2;
    Call_basic_Procedure...
---------

 If you truly do need all of the code inside of the Onchange event to take place for both events, USER or your
 code, then you can simply directly call the event from your code.

  Just call the Event directly..

 Like I said early, any events that get triggered from USER interactions of the control should not get triggered
when using CODE to directly change the same properties. In this case your code should be doing it instead.

 There are a few controls in the LIBS that call Onchange from both direct code or user interaction when they
really shouldn't be doing that, it causes confusion in code when you need to decide how the code got executed.


The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TPageControl
« Reply #2 on: February 14, 2018, 12:55:24 am »
This has been removed in version 1.8 for Delphi compatibility. See http://wiki.freepascal.org/Lazarus_1.8.0_release_notes#TCustomTabControl_setting_TabIndex_or_PageIndex_by_code.

When you read this you will learn that there is a simple fix: set the PageControl Option nboDoChangeOnSetIndex, and you will have the old behavior back.

You might want to read also the rest of the 1.8-release-notes to learn about other code-breaking changes.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 494
Re: TPageControl
« Reply #3 on: February 14, 2018, 03:54:58 am »
@WP

thank you

it's work
« Last Edit: February 16, 2018, 11:07:02 am by majid.ebru »

 

TinyPortal © 2005-2018