Recent

Author Topic: Wierd behaviour - Laz 1.6 >> Laz 2.2  (Read 9969 times)

BrunoK

  • Hero Member
  • *****
  • Posts: 682
  • Retired programmer
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #75 on: September 16, 2022, 06:01:29 pm »
So now to illustrate what I suggest you do
1°) in TForm1 private fields add fields
Code: Pascal  [Select][+][-]
  1. FFirstShown:Boolean;         // Form has been shown once
  2. FFocusWinControl:TWinControl;   // Delayed focusing
2°) Now DatePaidChange procedure :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DatePaidChange(Sender: TObject);
  2. begin
  3.   if using = 'C' then
  4.     ExtractDate(Invoice.Paid,DatePaid.date)
  5.   else
  6.     ExtractDate(Purchase.Paid,DatePaid.date);
  7.  
  8.   if not PayMeth.CanFocus then
  9.     FFocusWinControl := PayMeth // Set delayed focus control
  10.   else
  11.     PayMeth.SetFocus;      
  12. end;
3°) Now for TForm.OnShow insert this snippet of code :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormShow(Sender: TObject);
  2. { Your vars }
  3. begin
  4.   { Your code if any ... }
  5.  
  6.   if not FFirstShown then begin
  7.     FFirstShown := True;
  8.     if Assigned(FFocusWinControl) then begin
  9.       FFocusWinControl.SetFocus;
  10.       FFocusWinControl := nil; { not really necessary }
  11.     end;        
  12. end;

BrunoK

  • Hero Member
  • *****
  • Posts: 682
  • Retired programmer
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #76 on: September 16, 2022, 06:07:14 pm »
Replace CanFocus method by CanSetFocus method.

J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #77 on: September 16, 2022, 06:29:27 pm »
What would be the purpose of such additions to an already fully operational project?

As I've said, the program has been running on a (pretty much) daily basis for over 6 years and the only reason for an update is due to the VAT Man wanting all buisnesses to submit their VAT Return digitally. This entails me creating the ability to create a .CSV File containing up to 6 figures which third party software can read and submit to HMRC.  My own wish to do so at the [click of a mouse] was the only real reason, I could quite easily have created an Excel sheet manually (in fact I have done so for my past two returns).

The problems only arose because I updated from Lazarus 1.6 to Lazarus 2.2 and the subsequent discovery of an issue in 1.6 that was corrected in 2.2 along with what seems to be a glitch in the LCL.

Nothing in the code to create the .CSV file had any bearing upon the problem, it seems that was down to my glib use of 'SetFocus' at every opportunity :)


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Bart

  • Hero Member
  • *****
  • Posts: 5536
    • Bart en Mariska's Webstek
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #78 on: September 16, 2022, 10:46:03 pm »
As a workaround you may be able to prefix your event with something like
Code: Pascal  [Select][+][-]
  1. if not Form1.isVisible then exit;

Probably also works with "sender.isVisible".

Fixed in trunk.
You can easily adapt your local copy of Lazarus.
Open the file editbtn.pas
Find procedure TDateEdit.Loaded;
Replace it with this:
Code: Pascal  [Select][+][-]
  1. procedure TDateEdit.Loaded;
  2. begin
  3.   //Forces a valid Text in the control
  4.   if not (csDesigning in ComponentState) then
  5.     SetDate(FDate);
  6.   //avoid OnChange (regression introduced by #8ce29506c500e46d65b9a067bf446fd91224e6c0, happens when DirectInput=True and DefaultToday=True)
  7.   //the FEdit's OnChange is only forwarded once the whole component has been loaded, so call inherited after setting the text, not before
  8.   inherited Loaded;
  9. end;
Rebuild you application (this will rebuilt the LCL).

No workaround needed anymore.

Bart

J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #79 on: September 17, 2022, 01:33:05 am »
Thanks Bart, sorted !!

Two days ago I was seriously considering accepting that I would have to keep my Accounts Program under Laz 1.6 - yesterday seemed to bring welcome news that there was a 'work-around' which was not at all difficult and I was quite prepared to put up with it as a long term solution!

Now I see that all you have done is move 'inherited Loaded;' from the start of a procedure to the end, and all is sweetness and light !   incredible :)

The important fact though is that I'm now running the program without the 'work-around' and without errors. Along the way I've learned a great deal about Lazarus and the IDE  -  Result!

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #80 on: September 18, 2022, 05:31:55 pm »
!!!  Aaaaggggg  !!!

Now I'm REALLY confused :(

Today I had occasion to do some more debugging on a totally unrelated part of this project and came across the secondary problem again -- ie. switching between [Customer] & [Supplier] I got an error.  With my newfound knowledge of the CallStack taking me to the location of the error I found that a 'SetFocus' that I had commented out was 'live' again ?????

When I then looked at the header in the .PAS file - where I had made notes about under which Laz version it was working - those 'notes' were not there ????

I then looked at EditBtn.PAS to make sure that the change to TDateEdit.Loaded; proc hadn't been changed  - - - - -   imagine my surprise when searching for 'TDateEdit.Loaded;'  it was not to be found  ?????

By again commenting out the offending 'SetFocus' I'm back with a working program but the many 'SetFocus' lines that I had commented out are all back in operation  -  ????

I have certainly not removed the 'comment' markers (nor the 'Notes') and haven't touched EditBtn.pas since I made the edit suggested by Bart so am at a loss to explain what could have happened.

« Last Edit: September 18, 2022, 05:35:19 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10900
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #81 on: September 18, 2022, 05:42:23 pm »
!!!  Aaaaggggg  !!!

Now I'm REALLY confused :(

Today I had occasion to do some more debugging on a totally unrelated part of this project and came across the secondary problem again -- ie. switching between [Customer] & [Supplier] I got an error.  With my newfound knowledge of the CallStack taking me to the location of the error I found that a 'SetFocus' that I had commented out was 'live' again ?????

When I then looked at the header in the .PAS file - where I had made notes about under which Laz version it was working - those 'notes' were not there ????

Don't just check the file by name. Check which folder it is in.
And which folder you did the edit in (find the same file in all folders that may have copies). If it has the change, the file date likely tells you when you added that note.


If you did a "publish project", I don't immediately see how a mix up would have happen. But still, lets first make sure no cross project-copy file inclusion has happened.


J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #82 on: September 18, 2022, 05:59:17 pm »
I'm in the process of doing just that Martin  -  I've now discovered that all the editing I did regarding the VAT Return have vanished as well :(

I'll report back.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #83 on: September 18, 2022, 07:19:23 pm »
I've found the .PAS file with the 'SetFocus' commented out along with EditBtn.pas with the edited TDateChange Proc.

I suspect that I was somewhat cavalier this morning when I opened the project using the [Open Recent Project] option and didn't really look at the whole path  -  I can't be 100% but that looks to be the case.

Now I have a number of backup files --  !! thank the Lord for the suberb backup system within Lazarus !!  ---  but not all are the same date/time. This is obviously due to the fact that Laz doesn't bother to save unchanged files (quite correctly) but I'd appeciate guidance as to which files I need to make available in the correct folder.

At the same date/time (16th 23:16) I have .PAS,  LFM  &  .LPI  filles.  The .LPS file I have is 17th or 18th and the .RES file is 18th but is in the sub folder /LIB.

The .LPR and .ICO files are in the correct folder and unchanged from their creation in 2017.

It's quite obvious that the .PAS, .LFM & LPI files need to be made non-backup and moved to the correct folder but I'm not sure which .LPS file should joint them or whether the .RES file should be moved from /LIB.   I could 'suck-it-and-see' but I'd rather be advised by those with better knowledge :)

[EDIT]
I should also have asked if the Editbtn.pas file should be restored and to where?
I've now found that the only copy of Editbtn.pas without TDateEdit.Loaded is under Laz 1.6 so (I have no idea how) I must have been working under that at some point  :-[

Then there is the question of the files in the /LIB folder under the correct (working) folder . . . . . .

« Last Edit: September 18, 2022, 10:15:36 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 959
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #84 on: September 19, 2022, 10:15:24 am »
Panic over :)

Following the basic logic of restoring the backup files to the main folder - and clearing out older files to a 'safe' location - (just in case!)  -  I took the bull by the horns and opened the project.

Before I did a compile I made sure that the form showed the changes I'd made to the VAT element, that 'SetFocus' had been commented out and that Editbtn.pas did have TDateEdit.Loaded.

All those elements in place, I hit [F9] and I'm back to where I was on Saturday evening. I can't check on the small issue that made me look at the code again until I need to use that particular aspect though - that only happens three times a month - but at least I am aware.

Thanks again for your support.


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10900
  • Debugger - SynEdit - and more
    • wiki
Re: Wierd behaviour - Laz 1.6 >> Laz 2.2
« Reply #85 on: September 20, 2022, 03:41:35 am »

 

TinyPortal © 2005-2018