Recent

Author Topic: [Solved] Error 219 and -CR option  (Read 1021 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3533
[Solved] Error 219 and -CR option
« on: September 19, 2021, 06:02:53 pm »
Is there an inline directive with the same effect as disabling the compiler's -CR command-line option?

I've got an error 219 crept into a couple of places in the stuff I'm working on as the result of some refactoring. I know that (telling Lazarus to) not apply -CR fixes it, and would rather get back to a testable situation before working to eliminate the cause.

Basically, I've got a form with a field declared as a TThread since the thread's implementation is hidden. I know from experience that a class helper will allow me to refer to the field's actual content elsewhere, but also know (from experience :-) that one has to be careful with them particularly if visible across units. So what I'm doing this time round is subclassing the form and "surfacing" the field as its actual type... which causes an error 219 under some (but possibly not all) conditions.

MarkMLl
« Last Edit: September 20, 2021, 12:19:26 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3518
  • Compiler Developer
Re: Error 219 and -CR option
« Reply #1 on: September 20, 2021, 09:34:55 am »
The equivalent would be {$ObjectChecks Off}.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3533
Re: Error 219 and -CR option
« Reply #2 on: September 20, 2021, 10:22:20 am »
The equivalent would be {$ObjectChecks Off}.

Thanks for that. Doesn't fix it, I'll see if I can distil it to a test project since the way I'm approaching the issue avoids- in principle at least- casts scattered around all over the place.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 3533
Re: Error 219 and -CR option
« Reply #3 on: September 20, 2021, 11:33:43 am »
My usage of class helpers appears OK, the problem is caused by "surfacing" a property by casting via a subclassed form in the helper.

There's almost certainly a better way of doing it, but the objective is to break as many potential circular references and hide as many data types as possible.

Demo project attached, problem occurs using FPC 3.0 and 3.2. Any (polite :-) suggestions appreciated.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 3533
Re: Error 219 and -CR option
« Reply #4 on: September 20, 2021, 12:19:07 pm »
Got it I think: the fix appears to be to apply the directive at the (single) point where the field is surfaced, not (at the multiple places) where the errors were reported.

Code: Pascal  [Select][+][-]
  1. (* This is in lieu of attempting to have multiple per-unit helpers for the main *)
  2. (* form, since the semantics vary depending on compiler version and the errors  *)
  3. (* that result are obscure.                                                     *)
  4.  
  5. type
  6.   TlocalFormPSTalk= class(TFormPSTalk)  (* Used to "surface" fSerialThread      *)
  7.                       function getSerialThread(): TSerialThread;
  8.                     end;
  9.  
  10.  
  11. function TlocalFormPSTalk.getSerialThread(): TSerialThread;
  12.  
  13. begin
  14.   result := TSerialThread(fSerialThread)
  15. end { TlocalFormPSTalk.getSerialThread } ;
  16.  
  17.  
  18. type
  19.   TStationH=                            (* Avoid circular definition            *)
  20.     class helper for TStation
  21.     protected
  22.       function SerialThread(): TSerialThread; inline;
  23.     end;
  24.  
  25.  
  26. function TStationH.SerialThread(): TSerialThread;
  27.  
  28. begin
  29. {$push }{$ObjectChecks Off}
  30.   result := TlocalFormPSTalk(FormPSTalk).getSerialThread()
  31. {$pop }
  32. end { TStationH.SerialThread } ;
  33.  

This obviously is a desirable situation, since it localises all the dubious stuff (explicit casts etc.) in one place

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018