Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-05

getopts unit vs CustApp parameter handling

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Is the getopts unit deprecated or not recommended for usage? The reason I ask is because I see CustApp has similar functionality to the getopts unit, but the custapp has it’s own implementation - it doesn’t use the getopts am I not understanding the purpose of the getopts unit correctly?

Regards,
Graeme

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Hi, Is the getopts unit deprecated or not recommended for usage?

It is not deprecated.

Show quoted text 7 lines
The reason I ask is because I see CustApp has similar functionality to the getopts unit, but the custapp has it’s own implementation - it doesn’t use the getopts is roughly based on the unix getopts mechanism. Or am I not understanding the purpose of the getopts unit correctly?

They serve the same purpose, but function differently.

Simply use the one whose interface you like best.

Michael.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
They serve the same purpose, but function differently. Simply use the one whose interface you like best.

I'm used to the command line parameters handling of CustApp, but none of my applications are TCustomApp based. Plus CustApp gives no code reuse regarding command line parameters code. So I refactored the code out of TCustomApp into an Interface and Class implementing that interface. So now if I need good parameter list handling I simply mix in Interface Delegation into any of my applications. This seems to work very well thus far.

Would this be of interest to Free Pascal? If so, I can refactor the CustApp code to use the Interface too.

If you wanted to take a look, the code is in the fpg_cmdlineparams.pas unit in fpGUI. The ICmdLineParams interface and TfpgCmdLineParams class (ignore the other deprecated class in that unit).

https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_cmdlineparams.pas

Example usage:
See the nanoedit project in fpGUI:

https://github.com/graemeg/fpGUI/blob/develop/examples/apps/nanoedit/nanoedit.lpr

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 15 lines
On 2016-05-03 11:02, Michael Van Canneyt wrote: > They serve the same purpose, but function differently. > > Simply use the one whose interface you like best. I'm used to the command line parameters handling of CustApp, but none of my applications are TCustomApp based. Plus CustApp gives no code reuse regarding command line parameters code. So I refactored the code out of TCustomApp into an Interface and Class implementing that interface. So now if I need good parameter list handling I simply mix in Interface Delegation into any of my applications. This seems to work very well thus far. Would this be of interest to Free Pascal? If so, I can refactor the CustApp code to use the Interface too.

It would be, but you had better update your interface, various things have been added.

Michael.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
It would be, but you had better update your interface, various things have been added.

I assume you mean FPC 2.6.4 (what I used) verses FPC 3.x. Thanks for the tip, I’ll take a look tonight and update the code appropriately.

Regards,
Graeme

Graeme Geldenhuys
to Michael Van Canneyt: It would be, but you had better update your interface, various things have been added.…
Michael Van Canneyt wrote
It would be, but you had better update your interface, various things have been added.

I’ve updated the Interface last night to match that of FPC Trunk.

https://github.com/graemeg/fpGUI/blob/develop/src/corelib/fpg_cmdlineparams.pas

I was about to refactor the “CustApp” unit when I realised that if I change the TCustomApplication class to use the Interface Delegation (and very nice code reuse), then backwards compatibility with any existing TCustomApplication descendants will be broken. :-/ Probably not an option then, which is unfortunate. Unless you know of a different way it can be done?

Maybe introduce a new CustApp2 unit (terrible name I know), and mark the existing one as deprecated?

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp