Recent

Author Topic: Can't change DBNavigator's DataSource  (Read 5623 times)

Walmir

  • New Member
  • *
  • Posts: 39
Can't change DBNavigator's DataSource
« on: August 01, 2014, 08:56:50 pm »
Hi,
I placed a DBNavigator in a main form. It is to be used with many secondary forms and have its DataSource property set at OnActivate and OnShow of these forms, that are opende in various TabSheets.
The data controls are in a data module and the data aware controls are in the secondary forms.
But, if I open the first form and then open a second form, when a switch back to the first one, the DBNavigator continues locked to the last form opened. Even when I close the last form, the DBNavigator's DataSource don't change when the first form is shown.
All data are visible in both forms.
« Last Edit: August 01, 2014, 09:09:05 pm by Walmir »

Walmir

  • New Member
  • *
  • Posts: 39
Re: Can't change DBNavigator's DataSource
« Reply #1 on: August 07, 2014, 02:22:15 pm »
No one can help me with this?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Can't change DBNavigator's DataSource
« Reply #2 on: August 07, 2014, 02:33:37 pm »
Posting an example project may help. See my response in your other thread on the forum.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Can't change DBNavigator's DataSource
« Reply #3 on: August 07, 2014, 02:54:38 pm »
Hi,
I placed a DBNavigator in a main form. It is to be used with many secondary forms and have its DataSource property set at OnActivate and OnShow of these forms, that are opende in various TabSheets.
The data controls are in a data module and the data aware controls are in the secondary forms.
But, if I open the first form and then open a second form, when a switch back to the first one, the DBNavigator continues locked to the last form opened. Even when I close the last form, the DBNavigator's DataSource don't change when the first form is shown.
All data are visible in both forms.

Don't use the form's onActivate or onShow use the TPageControl onchange or similar events. It is very possible that the forms events will not be raised when they are parented and not free floating forms.

EDIT:
Not to mention that you minimize the interdependencies if you use the page control that is already part of the main form and not the secondary form's events and that is only a good thing
« Last Edit: August 07, 2014, 02:57:27 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Can't change DBNavigator's DataSource
« Reply #4 on: August 09, 2014, 01:11:25 am »
I had a look at your code.
You're doing work (assigning the datasource to the navigator) in FormActivate. If you place a showmessage in the FormActivate of your forms you'll see the FormActivate is never called. That's because your (child)-forms have a parent set.

OnActivate and OnDeactivate event handlers are not called if a forms parent property is set.

taaz already warned you for this but somehow you completly ignored this.
Don't use the form's onActivate or onShow use the TPageControl onchange or similar events. It is very possible that the forms events will not be raised when they are parented and not free floating forms.

You could perform a simple "hack" by calling the child-forms OnActivate manually in the OnChange event of your TTDINotebook on the mainform.

Code: [Select]
procedure TfrmMain.tdiAbasChange(Sender: TObject);
begin
  if tdiAbas.ActivePage is TTDIPage then
    if Assigned(TTDIPage(tdiAbas.ActivePage).FormInPage) then
      if Assigned(TTDIPage(tdiAbas.ActivePage).FormInPage.OnActivate) then
        TTDIPage(tdiAbas.ActivePage).FormInPage.OnActivate(nil);
end;

(please note that this is not a bug and has nothing to do with the earlier problems with dbnavigator and datasetactions.)

Walmir

  • New Member
  • *
  • Posts: 39
Re: Can't change DBNavigator's DataSource
« Reply #5 on: August 09, 2014, 06:00:32 pm »
Rvk and Tazz, thank you for your help.
Excuse me, I did not see Tazz post.

Walmir

  • New Member
  • *
  • Posts: 39
Re: Can't change DBNavigator's DataSource
« Reply #6 on: August 09, 2014, 06:59:42 pm »
Not to mention that you minimize the interdependencies if you use the page control that is already part of the main form and not the secondary form's events and that is only a good thing

What I'm doing here is migrate a Delphi MDI application to a Lazarus TDI one.
It seems that it is not so straightforward as I thought....

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Can't change DBNavigator's DataSource
« Reply #7 on: August 09, 2014, 07:07:20 pm »
It seems that it is not so straightforward as I thought....
Aaah... just a few tweaks here and there   ::) ;D
At least you're getting to know Lazarus/FPC really well :D
« Last Edit: August 09, 2014, 07:09:41 pm by rvk »

 

TinyPortal © 2005-2018