Recent

Author Topic: Detecting existing helpers  (Read 871 times)

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Detecting existing helpers
« on: October 15, 2019, 10:31:41 am »
My apologies if this is an FAQ. It's been explained to me in the past the extent to which helpers are chained, and that if you define a helper of a base class (etc.) when one already exists you can break things.

How does one find out whether a class (etc.) already has a helper or a chain of helpers?

From what I can see, the documentation doesn't automatically annotate a base type with This has a helper, see xxx even if elsewhere it describes helpers for that class, for example https://www.freepascal.org/docs-html/rtl/sysutils/tnativeuinthelper.html describes a helper but the base class https://www.freepascal.org/docs-html/rtl/system/nativeuint.html doesn't mention it.

Similarly, I don't think there's any runtime check that can be put in a unit defining a helper which indicates whether there is already one or more helpers for the base type. And I don't think there's anything in Lazarus (haven't checked the FP IDE recently) that can be used for a coding-time check.

Sorry if this sounds like a whine, but it all started when somebody mentioned string helpers in the forum yesterday and I went to the base type to look them up.

And finally, while I'm kvetching, could we please have some indication in the documentation of what version supports new features like https://www.freepascal.org/docs-html/rtl/sysutils/tstringhelper.html since people who- often for good reason- are using slightly older versions of the compiler are likely to end up in the same set of reference documentation when they have problems.

Here endeth the whinge.

MarkMLl




Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: Detecting existing helpers
« Reply #1 on: October 15, 2019, 11:36:04 am »
That documentation is for 3.0.4 and is correct. The official documentation is always for the latest release version (3.0.4)  only.
 Any later additions - about standard helpers - are available from the sources of the documentation from 3.2 and trunk (which you have to build yourself).
Before 2.6 there were no type helpers at all but that would mean you are using a really old version.
And only after 2.6 the sysutils (only that one, for the rtl and afaik) contains implemented helpers.
And type helpers for simple types were introduced  later. (I asked for them and Sven implemented it)
New features do not mean breaking code, usually they give just more options. And that won't be back-ported.
Same as any other language.

If you rely on current documentation you can never rely on past or future documentation.

In Lazarus, helpers only show up if the unit where they are defined is included, just as in code: are in scope.
I don't think a detection otherwise is in any way valuable or maybe even achievable.
« Last Edit: October 15, 2019, 12:00:09 pm by Thaddy »
also related to equus asinus.

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: Detecting existing helpers
« Reply #2 on: November 11, 2019, 09:35:27 am »
I promised a follow up:
Code: Pascal  [Select]
  1. {$mode objfpc}{$H+}
  2. uses sysutils; // where most of the default helpers are declared
  3. begin
  4. {$if declared(Tstringhelper)}writeln('test passed');{$endif}
  5. end.
Not perfect but likely what you want.
also related to equus asinus.

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: Detecting existing helpers
« Reply #3 on: November 11, 2019, 10:55:25 am »
Thanks, I'll take a look at that but from my POV the situation was more like:

* I've got a class, e.g. something unwieldy from a legacy Delphi app.

* A problem can best be fixed by moving stuff into a class helper.

* Is there a way to check whether the class already has a helper, so that when defining the new one I know that it has to be hooked onto an existing helper rather than onto the class directly?

Apropos my documentation whine, it wasn't so much that I was worried about new features breaking backward compatibility, but that since the online documentation always refers to the most recent version of the compiler it includes stuff which might not be applicable if an older one has to be used (e.g. a legacy project uses a specific version of Lazarus which mandates a certain version of FPC).

I've tried to look at this myself in the past (perhaps about ten years ago) and was able to build the documentation and generate a permuted index (so that e.g. it was possible to find all procedures that had "list" in their short description). In principle I should have been able to put a version number in front of every name hence document which version introduced a particular procedure, but in practice I hit problems caused- I think- by more-recent FPC utilities not liking some of the older files. In any event I got stuck, perhaps now that Docker makes running multiple versions easier I'll revisit this and see what I can come up with.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: Detecting existing helpers
« Reply #4 on: November 11, 2019, 11:27:34 am »
I am not aware that helpers can be detected - other than parsing all used units, which is what the Lazarus IDE does for code completion? - without testing for the helper name.
So do you know the helper name and possibly the unit it resides in?
also related to equus asinus.

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: Detecting existing helpers
« Reply #5 on: November 11, 2019, 11:49:25 am »
> So do you know the helper name and possibly the unit it resides in?

Hopefully this is something that won't catch /me/ again because I now have an understanding of the way that the helpers have to be set up as a chain rather than a tree. But I've had some right royal headscratching sessions when a helper got inadvertently hidden and the error messages appeared at the point where the hidden helper was being referenced... which of course was a long way from where the problem was caused by a bad declaration in the most-recently-added helper.

Sorry, I'm whining again :-)

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: Detecting existing helpers
« Reply #6 on: November 11, 2019, 12:34:17 pm »
Well, thinks improve: FPC supports helper inheritance and in trunk multiple helpers can be in scope at the same time.
Code: Pascal  [Select]
  1. {$mode objfpc}{$H+}{$modeswitch typehelpers}
  2. uses sysutils;
  3. type
  4.   TExtByteHelper = type helper(TByteHelper) for byte
  5.   { your extensions. original helper stays in scope }
  6.   end;
  7. begin
  8. end.
See also https://lists.freepascal.org/fpc-announce/2013-February/000587.html and new features 3.0

For trunk extensions see: https://wiki.freepascal.org/FPC_New_Features_Trunk#Support_for_multiple_active_helpers_per_type
« Last Edit: November 11, 2019, 12:44:12 pm by Thaddy »
also related to equus asinus.

PascalDragon

  • Hero Member
  • *****
  • Posts: 716
  • Compiler Developer
Re: Detecting existing helpers
« Reply #7 on: November 12, 2019, 03:32:13 pm »
Apropos my documentation whine, it wasn't so much that I was worried about new features breaking backward compatibility, but that since the online documentation always refers to the most recent version of the compiler it includes stuff which might not be applicable if an older one has to be used (e.g. a legacy project uses a specific version of Lazarus which mandates a certain version of FPC).

I've tried to look at this myself in the past (perhaps about ten years ago) and was able to build the documentation and generate a permuted index (so that e.g. it was possible to find all procedures that had "list" in their short description). In principle I should have been able to put a version number in front of every name hence document which version introduced a particular procedure, but in practice I hit problems caused- I think- by more-recent FPC utilities not liking some of the older files. In any event I got stuck, perhaps now that Docker makes running multiple versions easier I'll revisit this and see what I can come up with.
The documentation is also contained in the FPC downloads.
So let's say you need the documentation for 2.4.2. Then you go to e.g. SourceForge and locate the fpc-2.4.2.x86_64-linux.tar file (the platform doesn't really matter here, but the Linux tars are the most easy to access). Then you untar it and will find the documentation inside doc-pdf.tar.gz.

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: Detecting existing helpers
« Reply #8 on: November 12, 2019, 04:12:22 pm »
The documentation is also contained in the FPC downloads.
So let's say you need the documentation for 2.4.2. Then you go to e.g. SourceForge and locate the fpc-2.4.2.x86_64-linux.tar file (the platform doesn't really matter here, but the Linux tars are the most easy to access). Then you untar it and will find the documentation inside doc-pdf.tar.gz.

Thanks Sv, I'll try to find time to look at this again and will bear that in mind. I can't remember where I was breaking into the files, I might have been simply post-processing a PDF; in any event I think I've got my scripts etc.

Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.