Author Topic: Proper name for free method in old school objects  (Read 948 times)

LemonParty

  • Hero Member
  • *****
  • Posts: 651
Proper name for free method in old school objects
« on: August 16, 2026, 07:56:56 pm »
I have an old school object:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyObject = object {...}
And I need to do a clean up (free some things) when object is not needed anymore. What name should I use for freeing method? .Free?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

jamie

  • Hero Member
  • *****
  • Posts: 7937
Re: Proper name for free method in old school objects
« Reply #1 on: August 16, 2026, 08:02:38 pm »
Not sure about that, it depends if you dynamically create them with Virtual methods?

If they are not that type, then maybe CleanUp, but then again, Advanced records can have constructors so whatever I guess.

Jamie


The only true wisdom is knowing you know nothing

LemonParty

  • Hero Member
  • *****
  • Posts: 651
Re: Proper name for free method in old school objects
« Reply #2 on: August 16, 2026, 08:08:35 pm »
Jamie, do you think advanced records are better choice?
Because I can change objects to advanced records.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thausand

  • Hero Member
  • *****
  • Posts: 613
Re: Proper name for free method in old school objects
« Reply #3 on: August 16, 2026, 08:36:53 pm »
constructor/destructor can be name any thing that want. It common and use init / done (example Freevision).

documentation (chapter declaration also have init/done example) : https://www.freepascal.org/docs-html/current/ref/refch5.html#refse28.html
A docile goblin always follow HERMES.md

cdbc

  • Hero Member
  • *****
  • Posts: 2943
    • http://www.cdbc.dk
Re: Proper name for free method in old school objects
« Reply #4 on: August 16, 2026, 08:42:20 pm »
Hi
Back in the day, we traditionally used 'Init' for the constructor & 'Done' for the destructor, of our Object(s)... You'd often see code like this:
Code: Pascal  [Select][+][-]
  1. var myObj: PMyObject;
  2. begin
  3.   myObj:= new(PMyObject,Init(42,'Life');
  4.   writeln('(i) The meaning of ',myObj^.Text,' is ',myObj^.Value);
  5.   dispose(myObj,Done);
  6. end;
  7.  
This all started with Turbo Pascal 5.5 \o/
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

jamie

  • Hero Member
  • *****
  • Posts: 7937
Re: Proper name for free method in old school objects
« Reply #5 on: August 16, 2026, 09:54:48 pm »
if you don't have any inheritance in the OBJECT, you can replace it with an advanced Record and use finalize, Initialize, Copy operators to auto initiate it and clean it up in the background when it enters and leaves the Code body.

 You can even use the Operator overloads in a record.

  It's up to you .

  Would be nice if either the object model could do that and still keep its ability to inherit or make the RECORD be able to inherit in which that could look more like a C++ class!  :o

 Jamie
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: Proper name for free method in old school objects
« Reply #6 on: August 17, 2026, 08:28:56 am »
records with inheritance are called....wait for it... objects.. hence record inheritance will never happen because it is already in the language.
Any "programmer" that knows only one programming language is not a programmer

LemonParty

  • Hero Member
  • *****
  • Posts: 651
Re: Proper name for free method in old school objects
« Reply #7 on: August 17, 2026, 07:38:46 pm »
Thank you for answers. I stoped on advanced records for now.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018