Recent

Author Topic: Strange behaviour for "Class of TClass"  (Read 1340 times)

El Salvador

  • Full Member
  • ***
  • Posts: 134
Strange behaviour for "Class of TClass"
« on: June 30, 2020, 05:51:12 pm »
Hi everybody.

I'm started to porting my Delphi software to Lazarus, and I have a strange SigSegv. I'm using VirtualTree and TPageFrameClass as class of TfrmBaseEntityPage (base class for generic frame with some methods and properties) in its nodedata to show frame in a form and when I try to display.

I make a sample of this issue, to reproduce it. In Delphi I haven't problems, but in FPC 3.2 and Lazarus 2.1, I have a SIGSEGV here:
TfrmBaseEntityPage(FramePage).Title

What am I doing wrong?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Strange behaviour for "Class of TClass"
« Reply #1 on: July 01, 2020, 12:00:09 am »
Try the attached amended project which compiles and runs for me without error, though of course it does nothing.

The principal changes to your code are quite minor, marked with //<< in the main form's unit.
I removed a raft of redundant units from uses clauses, and changed from mode Delphi to to mode objfpc, but you could easily revert that if you prefer.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Strange behaviour for "Class of TClass"
« Reply #2 on: July 01, 2020, 01:10:11 am »
I am glad that you were able to get it to compile. I looked at your example and it seems the changes you made are similar to issues I have been seeing lately and that is with managed strings returning empty (NIL) under some conditions..

 I've switched back to using shortStrings in many areas now, it has solved a lot of problems on my end..
 
 I write half mixed code anyways between API calls and pure LCL stuff.

The only true wisdom is knowing you know nothing

El Salvador

  • Full Member
  • ***
  • Posts: 134
Re: Strange behaviour for "Class of TClass"
« Reply #3 on: July 01, 2020, 09:37:24 am »
Try the attached amended project which compiles and runs for me without error, though of course it does nothing.

The principal changes to your code are quite minor, marked with //<< in the main form's unit.
I removed a raft of redundant units from uses clauses, and changed from mode Delphi to to mode objfpc, but you could easily revert that if you prefer.
But you have changed this line of code from this:
Code: [Select]
FFrameGeneral  := AddFrameNode(vstListCategory, nil,TPageFrameClass(TfrmGeneralOptionsPage.Create(Self)));to this:
Code: [Select]
FFrameGeneral := GetNodeByFrameClass(vstListCategory, TfrmGeneralOptionsPage);
In this way, you will not add the frame in virtualtree and it does nothing. Anyway I solved the problem, removing TPageFrameClass ( = class of TfrmBaseEntityPage; ) and using base class TfrmBaseEntityPage, so I can call directly TfrmBaseEntityPage's properties and methods. But I didn't understand this behaviour of "Class Of" in FPC vs Delphi.

 

TinyPortal © 2005-2018