Recent

Author Topic: [compromise found] creating a new class with more automated generated things  (Read 643 times)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1642
  • Fifty shades of code.
    • Delphi & FreePascal
I try to explain as good as possible what I would like to have at the end of this adjusting.

1. I start a new "Application (LCL)" project
2. I create for that a new Unit over the file menu
Code: Pascal  [Select][+][-]
  1. unit Unit3;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes , SysUtils;
  9.  
  10. implementation
  11.  
  12. end.
3. above is generated automagical
4. I add this
Code: Pascal  [Select][+][-]
  1. type
  2.   TTest = class(TObject) // here I pressed enter
  3.  
  4.   end; // this was added automagical
5. now my question is, can I patch somewhere to have access to automatic add between "TTest" and "end;" more defaults?
Code: Pascal  [Select][+][-]
  1.   TTest = class(TObject)
  2.   // can I add somewhere in Lazarus IDE or source that here is more added?
  3.   end;

exemplary that it look like this when I press "Enter" after the first line
Code: Pascal  [Select][+][-]
  1.   TTest = class(TObject)
  2.     strict private
  3.     private
  4.     protected
  5.     public
  6.     published
  7.   end;

Is that possible or impossible?
« Last Edit: March 06, 2023, 04:25:21 am by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Blaazen

  • Hero Member
  • *****
  • Posts: 3235
  • POKE 54296,15
    • Eye-Candy Controls
Re: creating a new class with more automated generated things, possible?
« Reply #1 on: March 06, 2023, 12:41:14 am »
I don't know if it is possible but I use lot Editor Macros for this.
Ctrl+L and then 1,2,3 or 4 writes private, protected, public or published for me.

Another possibility are Code Templates. It can be easily configured that you write - for example:

pri

and hit [space] or [enter] and it will expand to
private
protected
public
published
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Thaddy

  • Hero Member
  • *****
  • Posts: 13208
Re: creating a new class with more automated generated things, possible?
« Reply #2 on: March 06, 2023, 01:43:31 am »
It has been possible since ions ago to automagically create classes and even complete frameworks based on just a proper UML design input.
I know of three of those that were or still are available for Delphi, one of which generates code that is 100% compatible with FPC in mode delphi and was bundled with D5, D6 and D7 enterprise/architect editions and later available separately: modelmaker. (I still use that!)
Another one was bundled from Delphi 2006 onwards and a third one a very expensive but superb solution available separately. If you are still having any of those Delphi versions with a license higher that  professional, you know the products. Except for maybe the last one, called "Enterprise Architect" and still available.(It is more than a code generator: it is a well focussed UML solution that covers all UML design steps, I also use that)
All three of those need a thorough understanding of all steps in UML software design. All three are basically restricted to programmers and - since they are geared towards team - need well versed programmers, read university CS graduates that command UML- to be of any use.
I think few on the forum have ever used those, but I know there are at least 4-5 more than just me alone.

All these three solutions create the boiler plate classes, connections and events and even an application. You need only program the inner logic based on your own software design phases. Highly structured.
« Last Edit: March 06, 2023, 02:20:26 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1642
  • Fifty shades of code.
    • Delphi & FreePascal
Re: creating a new class with more automated generated things, possible?
« Reply #3 on: March 06, 2023, 01:54:17 am »
@Blaazen: Thanks for your input, but somehow I search for a solution where I do not need to interact, just pressing return after line #1 and the rest appear on its own
 - at least that is my wish  :-* :-* :-*
@Thaddy: How does your text help me? I mean, cool that you know a secret and it is possible somehow. Applause. But would you mind telling me how? :D
 - my wish is not create anything special or fancy, my wish is simple, I press "Enter" after a class definition and abracadabra, my wanted text from post #1 is there.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 13208
Re: creating a new class with more automated generated things, possible?
« Reply #4 on: March 06, 2023, 02:35:11 am »
I editted my post:
- modelmaker, included in Delphi enterprise and architect distributions
- enterprise architect from sparxsystems.com. Not to be confused with the above. It is language agnostic.
https://www.sparxsystems.com/enterprise_architect_user_guide/15.2//model_domains/cgo_dprops.html

I am sure I will find the third one, but I have to look up the Delphi versions after D7 and I just learned that Uwe Raab, a well known and respected Delphi guru, has even a modelmaker plugin for Delphi 10.3 and later:
https://www.mmx-delphi.de/2019/01/14/modelmaker-ide-integration-expert-for-delphi-10-3-rio-released/
Alas, the product is no longer available.

Both those can generate almost complete classes based on UML knowledge.

Maybe they offer trial versions?
Or maybe you have an appropiate Delphi 7 license and check it out?

Point is: it is not only possible, it is there in the wild and expensive.
Both are not really suited for the average single programmer but both go way beyond what is asked.

There is also an open source Delphi class builder, but I have to search all my left-over hard disks for that.
It was reasonable, though, after I fixed it... It worked on FPC2.6 and an old Lazarus.
« Last Edit: March 06, 2023, 02:44:08 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1642
  • Fifty shades of code.
    • Delphi & FreePascal
Re: creating a new class with more automated generated things, possible?
« Reply #5 on: March 06, 2023, 03:36:53 am »
@Thaddy, I really appreciate your words, but that sound way to overkill as what I actual try to achieve.
Thank you very much for your input, please not search for more things in that direction.
ClassBuilder, ModelMaker etc, all that is 100% more than what I needed :D

I try explain again my really really plain needing, where I thought it would be easy possible:
I do enter "TTest = class" and press enter, since the IDE (Lazarus) is adding automagical the "end;" I thought that it would be more easy possible to put my wanted lines before the "end;", no autogenerating of a full class with creators destructors etc etc etc, just those simple plain lines because I type them currently again and again and again.

Does someone know where in IDE (or Lazarus source) the magic happen where "end;" is generated after pressing return on line "TTest = class" ?

If nobody knows, I ride on Blaazens wave and search for how I create a hotkey/macro to insert those lines in IDE CodeEditor.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Wallaby

  • Jr. Member
  • **
  • Posts: 70
Re: creating a new class with more automated generated things, possible?
« Reply #6 on: March 06, 2023, 03:59:32 am »
It's probably hard-coded. You may be able to use the templates instead.

Try typing classc and press Ctrl + J. It will expand into:

Code: Pascal  [Select][+][-]
  1.   ClassName = class(InheritedClass)
  2.   private
  3.  
  4.   protected
  5.  
  6.   public
  7.    
  8.     constructor Create; override;
  9.     destructor Destroy; override;
  10.   published
  11.   end;  
  12.  
You can define your own templates too.

Blaazen

  • Hero Member
  • *****
  • Posts: 3235
  • POKE 54296,15
    • Eye-Candy Controls
Re: creating a new class with more automated generated things, possible?
« Reply #7 on: March 06, 2023, 04:02:32 am »
There are three predefined templates (Tools -> Code Templates ...): classc, classd and classf

 But you must at first set one of checkboxes to make template active: space, enter or so.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1642
  • Fifty shades of code.
    • Delphi & FreePascal
Re: creating a new class with more automated generated things, possible?
« Reply #8 on: March 06, 2023, 04:23:50 am »
@Wallaby, Blaazen: That solution is something I can live with, I didn't know that, and it is easy adjustable for my needs, thank you for that!
And cool, what else I do find in there, a new playground for so many things  :D :D :D
Wow, IDE is cool when you know what it can do for you  :-* :-* :-*

It's probably hard-coded.
That was also my thinking where I had my big wish to patch the hard coded with my lines in...
but with that CTRL+J thing after entering a placeholder it might be not needed to be overridden anymore.
(the wish to patch is still there  >:D  O:-))
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

 

TinyPortal © 2005-2018