Recent

Author Topic: Class designer/editor  (Read 1992 times)

eedeeota

  • Newbie
  • Posts: 2
Class designer/editor
« on: September 11, 2024, 10:47:48 am »
Hello everyone.
Maybe I mistaken, but I read on Google (can't recall precisely where) that Lazarus has a Class designer wizard, something that you input a Class' name, its Methods' and Attributes' names, then it will generate Pascal Code.
Is this true, or am I mistaken?

Thanks in advance for any help.
Regards, have a nice day.

Thaddy

  • Hero Member
  • *****
  • Posts: 15722
  • Censorship about opinions does not belong here.
Re: Class designer/editor
« Reply #1 on: September 11, 2024, 10:54:34 am »
Such software certainly exists, but I am not aware that Lazarus contains such a feature.
An example is e.g. ModelMaker that came with several versions of Delphi and is written in object pascal.
There are several others.
I suppose some of them are translated to FreePascal.
( I know for sure about one, because I translated it. Closed source, alas, not an excuse but true )
« Last Edit: September 11, 2024, 10:56:20 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

dseligo

  • Hero Member
  • *****
  • Posts: 1372
Re: Class designer/editor
« Reply #2 on: September 11, 2024, 11:19:16 am »
Hello everyone.
Maybe I mistaken, but I read on Google (can't recall precisely where) that Lazarus has a Class designer wizard, something that you input a Class' name, its Methods' and Attributes' names, then it will generate Pascal Code.
Is this true, or am I mistaken?

Thanks in advance for any help.
Regards, have a nice day.

Do you mean class completion?
https://wiki.freepascal.org/Lazarus_IDE_Tools#Class_Completion

eedeeota

  • Newbie
  • Posts: 2
Re: Class designer/editor
« Reply #3 on: September 12, 2024, 08:23:41 am »
No, it's not class completion.
I certainly mistaken what I saw.

Excuse me.

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Class designer/editor
« Reply #4 on: September 12, 2024, 03:10:32 pm »
Hello everyone.
Maybe I mistaken, but I read on Google (can't recall precisely where) that Lazarus has a Class designer wizard, something that you input a Class' name, its Methods' and Attributes' names, then it will generate Pascal Code.
Is this true, or am I mistaken?

Thanks in advance for any help.
Regards, have a nice day.
Hi @eedeeota this is something I am working on as a future feature (maybe) for the Lazarus IDE. The attached zip file contains the code. You can easily extend it to do whatever you want. The first screenshot is what you will see when you first compile and run. The second screenshot shows the code generated with user-entered data. Have fun.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

VisualLab

  • Sr. Member
  • ****
  • Posts: 492
Re: Class designer/editor
« Reply #5 on: September 12, 2024, 04:30:31 pm »
Aruna, are you planning to extend the class skeleton generator? For example, with:
  • field declaration section (private, protected),
  • method declaration section (private, protected, public),
  • property declaration section (protected, public, published),
  • properties associated with fields in the class,
  • fields (and associated with them properties) handling events (e.g. OnClick: TNotifyEvent),
  • accessors for fields (GetX, SetX) and where to declare them (private, protected),
  • indicating that the property being added is read-only,
  • indicating that the read-only property being added has an accessor method (GetX),
  • indicating that the method being added is overloaded,
  • indicating that the method being added is virtual,
  • indicating that the method being added is overrided.
Of course, this does not exhaust the needs of generating a class template.
« Last Edit: September 12, 2024, 04:33:03 pm by VisualLab »

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Class designer/editor
« Reply #6 on: September 12, 2024, 05:16:37 pm »
Aruna, are you planning to extend the class skeleton generator?
God forbid NO!

I mean not at this moment in time I do not know enough about how to go about doing things. What I shared was a simple learning experiment for myself which I felt may help the OP. Maybe one day yes but right now this is not a task I want to take on alone. If I had other people to work on this together then yes. Else right now thank you for asking but hell NO am not going bald again!

For example, with:
  • field declaration section (private, protected),
  • method declaration section (private, protected, public),
  • property declaration section (protected, public, published),
  • properties associated with fields in the class,
  • fields (and associated with them properties) handling events (e.g. OnClick: TNotifyEvent),
  • accessors for fields (GetX, SetX) and where to declare them (private, protected),
  • indicating that the property being added is read-only,
  • indicating that the read-only property being added has an accessor method (GetX),
  • indicating that the method being added is overloaded,
  • indicating that the method being added is virtual,
  • indicating that the method being added is overrided.
Of course, this does not exhaust the needs of generating a class template.
You see? I did not even know about a single one of these you just described and you want me to put together a full-fledged error-free tool that generates clean modular reusable code with no variable collisons ( I wish.. sigh!)

EDIT: Okay correction: I know about some of these yes, but I can't say that I fully  understand how these methods can be used. Maybe I will write-up a page on the wiki describing these and how to access and use them?
« Last Edit: September 12, 2024, 05:32:16 pm by Aruna »
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Class designer/editor
« Reply #7 on: September 12, 2024, 10:10:45 pm »
Aruna, are you planning to extend the class skeleton generator?
I changed my mind, yes that is the plan now, to extend slowly as and when I fully understand things. It will be a very slow process.

For example, with:
  • field declaration section (private, protected),
  • method declaration section (private, protected, public),
  • property declaration section (protected, public, published),
  • properties associated with fields in the class,
  • fields (and associated with them properties) handling events (e.g. OnClick: TNotifyEvent),
  • accessors for fields (GetX, SetX) and where to declare them (private, protected),
  • indicating that the property being added is read-only,
  • indicating that the read-only property being added has an accessor method (GetX),
  • indicating that the method being added is overloaded,
  • indicating that the method being added is virtual,
  • indicating that the method being added is overrided.
Of course, this does not exhaust the needs of generating a class template.
VisualLab, would you please give me some more of the above which you feel are relevant or point me towards documentation a simple mind like mine can understand, please. And if you were me how would you go about doing this in the first place? IS what I have done a good start or ??
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

VisualLab

  • Sr. Member
  • ****
  • Posts: 492
Re: Class designer/editor
« Reply #8 on: September 13, 2024, 12:18:52 am »
...and you want me to put together a full-fledged error-free tool that generates clean modular reusable code with no variable collisons

No :) It was really just a question.

Aruna, are you planning to extend the class skeleton generator?
I changed my mind, yes that is the plan now, to extend slowly as and when I fully understand things.

Let me ask out of curiosity why you changed your mind?

It will be a very slow process.

Definitely (mainly because of the need to perform a lot of different tests, but not only).

For example, with:
  • field declaration section (private, protected),
  • method declaration section (private, protected, public),
  • property declaration section (protected, public, published),
  • properties associated with fields in the class,
  • fields (and associated with them properties) handling events (e.g. OnClick: TNotifyEvent),
  • accessors for fields (GetX, SetX) and where to declare them (private, protected),
  • indicating that the property being added is read-only,
  • indicating that the read-only property being added has an accessor method (GetX),
  • indicating that the method being added is overloaded,
  • indicating that the method being added is virtual,
  • indicating that the method being added is overrided.
Of course, this does not exhaust the needs of generating a class template.
VisualLab, would you please give me some more of the above which you feel are relevant or point me towards documentation a simple mind like mine can understand, please. And if you were me how would you go about doing this in the first place? IS what I have done a good start or ??

What I listed, I wrote from memory (i.e. basic elements of classes, of course not every class has to have all of them). As for documentation, when I was learning Object Pascal I used Delphi manuals. And I still do, but now I just supplement my knowledge with new elements. And I check the difference between what the FPC compiler (lazarus) supports (or doesn't support) and what the DCC compiler (Delphi) supports. I think a good manual to start with would be the one written by Marco Cantu "Delphi Object Pascal Handbook". Details about classes are described on pages: 202 - 352. Unfortunately, the manual requires registration.

And if you were me how would you go about doing this in the first place? IS what I have done a good start or ??

Hmm, I can only write how I would do it (everyone probably has a slightly different approach when implementing a project). But just quickly...

In any case, I would take as a basis the guidelines that I have already mentioned (and these are only the basic elements of classes, because there are more of them). I would start by designing a GUI for a class skeleton generator. It should have extensive class skeleton configuration options and at the same time be easy to use. And this is where the difficulty lies, because these are contradictory requirements. Large configuration possibilities require an extensive GUI, which is usually not easy to use. When configuring the class skeleton, certain components should be blocked/inactive (or not displayed at all), because they can be mutually exclusive.

To start with, I would make the prototype as a separate program and avoid dialog boxes (they require too much clicking). The first versions of such a project would certainly be very temporary and the GUI would probably change significantly from version to version. What's more, I am afraid that the first few versions of the prototype would have to be devoted to testing several different concepts in order to check their ergonomics (which one is the most useful or the least inconvenient to use).

At the moment I don't have a clear idea of ​​what the generator workspace (GUI) would look like. It would probably be a collection of controls placed in 2 columns. In the first column there would be labels. In the second there would be edit fields, drop-down lists (combo-boxes), view lists, check-boxes, etc.

The generator program created in this way would produce the class skeleton code. A preview of this code could be placed in a multi-line edit field (e.g. TMemo or better in TSynEdit associated with TSynFreePascalSyn). Then this class skeleton code would have to be tested in Lazarus. If it worked without errors, then we could start thinking about how to link it to Lazarus, that is, how to pass code from the class skeleton generator to the source code editor in Lazarus (here you would have to look into the Lazarus sources, which can be very time-consuming).



EDIT (13-09-2024): I forgot the most important thing – you need a data container (e.g. TClassSkeleton) that will:
  • store the skeleton structure of the class (not the source code!),
  • make the components available for editing,
  • allow you to save the skeleton of the class from the container to a file (e.g. XML),
  • allow you to load the skeleton of the class from a file to the container,
  • be used to generate the source code of the class.
To do this, you would need to design sub-containers contained in the main container. Each sub-container would store some part of the skeleton of the class: a field, a method, a property, an event, a constructor, a destructor.

It would probably be advisable to also design a controller and views (dividing tasks between components based on the MVC pattern). Views would allow the content of the class skeleton elements to be made available for editing and viewing.

One of the views would be an editor of the class skeleton elements. It could be prepared as a platform (e.g. TGroupBox) on which there would be controls such as edit fields, drop-down lists, switches, buttons, etc. along with appropriate labels.

Another view could be in a tabular form (e.g. TListView set as a report). This list could display content retrieved from subcontainers. Selecting an item on the list would cause the content of such a subcontainer to be displayed in the editor controls. Buttons would also be needed to allow adding new elements of the class skeleton.

Perhaps it would also be necessary to prepare a source code generator. The generator would provide the source code to a preview control (e.g. TSynEdit), which would act as one of the views.

The controller would coordinate the whole operation, e.g. after committing changes in the editor it would force a refresh of content in the views: (1) the table of class elements and (2) the source code preview. The controller could be notified about the state of the container or views using events originating from them.
« Last Edit: September 13, 2024, 10:50:58 pm by VisualLab »

avra

  • Hero Member
  • *****
  • Posts: 2528
    • Additional info
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Warfley

  • Hero Member
  • *****
  • Posts: 1603
Re: Class designer/editor
« Reply #10 on: September 13, 2024, 11:17:49 am »
I'm always amazed with such generators, because if writing the boilerplate for a class is the bottleneck for your implementing speed, you're either writing to many classes, or to little actual algorithmic functionality.

Like I understand UML modelling, when you first design your whole project structrue and then generate your whole structure at once, but just generating a single class from a list of attributes? Like writing it out should not be a notable efficiency loss at any scale

VisualLab

  • Sr. Member
  • ****
  • Posts: 492
Re: Class designer/editor
« Reply #11 on: September 13, 2024, 12:41:07 pm »
https://wiki.freepascal.org/UML,_modelling_tools,_code_generators_and_code_analysis_tools

I really like diagrams and schemes because they make work easier (especially design). They are common in many technical fields (e.g. electronics, digital technology, hydraulics, kinematics, process engineering, chemical transformations, etc.). You can "take in the whole project at a glance". Therefore, using them in software engineering is tempting, because a lot of the work will be done by the software, in this case CASE, for humans (or at least that's what one might assume). I am familiar with most of the CASE tools mentioned. At some point I got to know them a little bit. But I've never actually used them in any of my projects. The reason was that you had to click a lot to get the expected effect (which was time-consuming). Then I stopped using them and I haven't had any contact with them for over 10 years. Of course, they have their advantages. However, not always and not everyone has the need to use them.

But... what I'm discussing here with Aruna is something else. In no way did I mean creating a class generator similar to CASE tools! My suggestion would be to make it a simple single window program. It would be used to quickly generate the skeleton code of ONE class. When you create a class, you have to write a lot of code that is repeated in many classes (sometimes referred to as a "boilerplate"). So let the program generate it, and the programmer just tell him what to put in this skeleton. And then, after transferring the skeleton code of the class to the Lazarus editor, the programmer will add the instructions that are specific to the class being created. This software should be relatively easy to use and require as little clicking as possible (as possible).

Yesterday, just before going to bed, I had another idea that the options selected in the skeleton code generator could be saved to a file (e.g. XML). Such a set of options could be loaded into the class generator, so that you don't have to click everything again every time. However, for now, these are just loose discussions (digressions).

Joanna

  • Hero Member
  • *****
  • Posts: 1098
Re: Class designer/editor
« Reply #12 on: September 14, 2024, 01:47:03 am »
Quote
I was havng getting Lazarus to compile from scratch on QEMU running Debian 12 bookworm
Hi aruna glad you got it figured out.
 It might be useful to make a step by step guide of how you did it for future reference
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Class designer/editor
« Reply #13 on: September 14, 2024, 02:03:11 am »
Quote
I was havng getting Lazarus to compile from scratch on QEMU running Debian 12 bookworm
Hi aruna glad you got it figured out.
 It might be useful to make a step by step guide of how you did it for future reference
Hi Joanna, I’m glad I finally managed to sort it out with help from you and kee. Thanks for the suggestion,  I’ll definitely put together a step-by-step guide for future reference—it could be really helpful!
« Last Edit: September 14, 2024, 02:51:27 am by Aruna »
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: Class designer/editor
« Reply #14 on: September 14, 2024, 07:56:47 pm »
At the moment I don't have a clear idea of ​​what the generator workspace (GUI) would look like. It would probably be a collection of controls placed in 2 columns. In the first column there would be labels. In the second there would be edit fields, drop-down lists (combo-boxes), view lists, check-boxes, etc.
@VisualLab what do you think of the screenshot? :-)
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

 

TinyPortal © 2005-2018