Delphi code generation - delphi

I need to speed up my coding, too much work, so I need be able to generate code.
Any tools, any ideas?

Delphi includes Live Templates, a completely scriptable and configurable system for generating code constructs of any size or complexity.
Live Templates are, in my view, one of the more under-appreciated features in Delphi.
Find out how to use them at: http://delphi.wikia.com/wiki/Delphi_Live_Templates
and
http://delphi.wikia.com/wiki/Live_Templates_Technical_Info
Live templates are completely scriptable, meaning you can write Delphi code to do whatever you want with them.
An extendable example can be found here:
http://cc.codegear.com/Item/26420

Not a very good idea IMHO. If you need generator, then probably you have lots of code that looks very similar, so instead of generator, better thing would be to rethink and refactor code you have.
That should result in less code that is easier to maintain and less code in future for similar tasks.
If you are doing database application, then you could use some good visual SQL query builder to help you create queries. That is part that Delphi was not very good (I don't know if it improved in D2007 and D2009)
EDIT - Regarding SQL generation
There's lots of comments about query builder.
Well, I suppose I'm spoiled. As I remember, Delphi before version 6 (or maybe even 5?), had decent visual query builder. I had 0 (zero) bugs in SQL when I selected fields in query designer, opposed to writing SQL by myself.
SQL is just string in Delphi, there is no compiler checking, so this was the best way to ensure that SQL is correctly written.

If you mean something like a modeling tool, you could try out ModelMaker.

Rather than trying to code generate, you should probably just obtain code to do the bulk of what you want to do.
There are hundreds of free products at Sourceforge for Delphi.
And there are hundreds of thousands of code samples at Google Code Search that you can use.
Plus lots thousands of free or purchaseable components at repositories such as Torry's Delphi Pages or Embarcadero's Code Central for Delphi
Using components already made is the fastest way to speed up your coding, and to add capabilities that you would never have been able to.

For me best way is by creating custom components, and then create designer for this component.
I have find that i spent most of the time writing code that read/write values from controls. So i created control that can read, write, validate values, and automatically fill form or stored procedure or directly generate SQL and execute.
Custom designer allows you to setup all properties easy. Now i don't write code for such trivial task i just put control , open designer and set properties and rules that must be satisfied.

ModelMaker Code Explorer speed up my coding in times. It has a nice hotkeys for synchronising implementation and declaration, so if you changed one, you don't have to search for it pair. Also, very nice feature is, method editing dialog. And many more.

Have you tried GExpert? It is a set of tools built to increase the productivity of Delphi and C++Builder programmers by adding several features to the IDE. GExperts is developed as Open Source software.
Other alternative is using project template by saving a framework into the IDE Repository, create your own components and frames.

I wrote a code generator calle CodeTypo. I'm used it in many production environment. You can find it here: http://dade2000.altervista.org/index.php?page=CodeTypo
It's still in beta phase but is usable and reasonably stable.
I'll migrate all content of this old site in the new one (www.danieleteti.it) in english. And I'll add some other info about CodeTypo and code generators.

The thing that sped up my Delphi coding the most was getting CodeRush for Delphi (via a DevExpress VCL subscription for Delphi 5, 6, 7) and setting up a ton of templates.

Related

Usage for LiveBinding

I don't understand LiveBinding's purpose. I would like to know which are the cases in which LiveBinding is most valuable. Embarcadero's manual describes it: "LiveBindings is a data-binding feature supported by both the VCL and FireMonkey frameworks in RAD Studio. LiveBindings is an expression-based framework, which means it uses binding expressions to bind objects to other objects or to dataset fields".
Thanks but I still don't know more than before.
I have seen some video in which a guy spends 12 minutes and hundredths of clicks to connect the caption of a TLabel to a TListBox control. When the user clicks an item in ListBox the name of the item is shown in Label. I could have done that with a single line of code (few keystrokes and no mouse clicks).
I am not criticizing LiveBinding. I am saying that I don't understand where it is helpful. I am missing something. Since it is not doing something that cannot be done from code, it means it's doing something that can be done from code, but visually and much much faster. I admit I haven't invested a lot of time in this topic but everywhere I look I see a terribly convoluted way (come on, you really need 5 extra controls to make LiveBinding works?) to do a simple task.
Also, it seems that LiveBinding was mostly designed for DB. All examples will include some kind of DB connectivity. But I am expressly interested only about the cases where I can use LiveBindings and there is no data set/DB involved. I am not using DB that much.
I doubt v. much that anyone would use live bindings if they could use traditional db-aware VCL components. However, that's not an option for non-VCL projects (Android, Apple, etc) and live bindings is the only Emba-supplied option for delivering data to those from TDataSet descendants.
An advantage of live bindings is that in addition to the Android and Apple targets, you can use them in Windows apps, so conceivably you could write the same (FMX-based) application for all three.
Libe-binding can also be used in VCL applications, but tbh, I can't imagine why anyone would use live bindings if they were only targeting a Windows DB application, as they are much slower than the traditional db-aware controls, especially multi-row ones such as grids.
I have not tried myself, but because the implementation of live bindings is interface-based, its potential use extends far beyond DB applications, but you would have to implement the interfaces yourself. It seems to be based around a fairly abstract expression-evaluation engine.
Setting up a l.b. project in the IDE does seem to require quite a bit more clicking around than you'd be used to from a traditional VCL app, but that's mostly because there is an additional step involved where you tell the IDE how to bind the gui objects to the data source(s). However, it is quite straightforward to "wire up" live bindings entirely in code if you want to.

Can I set up database connections in Qt without writing code (like in Delphi)?

Although it is comparatively hard to write in C++ than in Pascal I'm really attracted by multi-platform support of Qt. I can connect to an MSSQL server running on Win2003 server from Linux or I can connect to a PostGreSQL server running on Linux. That made a plus when comparing with Delphi.
I'm trying to write sample programs to get used to the Qt and C++. So far I'm comfortable with the layouts and signals-and-slots mechanism (still double clicking the buttons to write event code though :) ). I wish I was using the SQL data in my programs as easily as in Delphi.
Is there any way that I can put some connection object, a DataSource, a DBGrid and a DBNavigator on to a form and go on without writing code? (For some forms it is really a time saver, a project with 300+ forms can be made faster)
I would like to hear from people using Qt with data from SQL servers.
You would have to write your own designer plugins to achieve that and make your widgets invisible, as there is no direct support for non gui components in Qt Designer.
However, writing explicit code in Qt (which is really a lot less work than in most other programming environments) helps the program to stay readable. Delphi projects with a lot of forms and components tend to become readable to the author alone, because dependencies jump across files a lot. If you store your forms in binary format, you are lost anyway, because you then cannot search your project textually to find dependencies.
Good design, which causes your code to become small and easily readable is necessary in any programming environment and makes aspects like invisible components in forms less important (though you will miss them for a while to come like I do).
So, unfortunately, you are on your own for the moment.

Best Practice in Delphi Rapid Application Development in term of Reusability [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How to improve our productivity when starting new project using Delphi?
For me, I create a template project including splash screen, primary data module with default component and all data-aware subroutines (open, close, query, default when failed to open DB, etc), and save the template in my repository. (I use all my own frames and unit in the project, so everything always be created automatically when I choose : New Project and choosing my template.)
Questions:
Is there any other way to improve reusability using Delphi?
What free open source framework (like Jedi) / IDE PLugins (like GExpert) you think is best to use using Delphi?
Pardon me if this question has been asked before.
For Q1: Use mature libraries which do for you the grunt work: DevExpress -or- TMS for UI (JEDI's JVCL also is very good), FastReport for reporting. Choose also a good connectivity framework (it depends on your db back-end) in order to have many day-to-day tasks solved OOTB. Also, if you're familiar with OPF have a look at InstantObjects. I heard that's very nice.
For Q2: See the IDE enchancements from cnpack.org
Also it will help to slowly build your own specialized framework/set of tools. Not something very big but as a quick way to get some things done in your way. Always try to design for reuse, even if it takes a little bit longer in the beginning.
For larger applications, the key to productivity is to work at a higher abstraction level than data module and database.
The database has a small set of types. In your domain you are likely to have default mappings from domain types to database types. You'll also have validators and formatters for them.
You'll have default reports, filters and search (windows, panels, sql queries) for your domain entities. You'll have role-based access control to them.
Take a look at domain-driven development.
One of my big gains in reusability in recent years has been moving to an ORM layer (I use tiopf) to separate out my business objects from the database.
As an example, I have db persisted, background threaded email objects. To add them to another application, I add in the required units and add a few lines of configuration (table/field mapping). Similarly I have user objects, generic lookup lists and the like all of which can be added to different projects for the price of initial configuration. This works on different databases without any changes other than configuration.
tiopf is my ORM of choice (read my overview here) but there are numerous others.
Defining the exact range of applications you want to make is a good first step. Improving productivity is nearly always related to specialization. General tools is just an extremely small percentile of productivity. I'd rather search (or make) specialized frameworks in my line of work if I really wanted to boost productivity.
I don't use GExperts, or another plugin. I don't benefit greatly (being able to grep just fine on the cmdline) in productivity, and any crash that can be avoided due to problems in the plugin is then a pre.
I used ModelMaker with Delphi. It is really nice tool that lets you draw objects and then can generate code based on templates you write.
It can speed up things when there is number of similar classes in project.
For Q2: GExperts is useful. The grep search comes in particularly handy, although the search / replace can cause odd side affects (inserting characters it shouldn't!).
I know you mentioned free / open source, but Castalia is very good. The refactoring methods work well and I like the structural highlighting, which makes it much easier to work with code (I did originally use CodeRush for this but it went Visual Studio only). The Bookmark stack is also handy for quick going back and forth through code.
Also, if you are a team, look for ways to improve your development process. Besides using Delphi as your implementation language, what are your project management methods? What source code management system do you use? What is your build system? Do you use automated testing methods? etc.
When I introduced Scrum at a previous employer, we got an almost immediate 50% improvement in team productivity. So check out the various Agile methodologies.
For true reusability, try to think in interfaces and try to black box as much as possible. Patterns are everywhere, research them and put them into practice.
When dealing with objects, as much as possible use the abstract, or an interface rather than a concrete implementation. Just be careful of taking this too far. Too many abastractions can add complexity and make debugging harder.
Units containing your business rules should be used by your gui. Units containing business rules should never themselves directly use gui units.
When I ask questions like this about "what is the best thing to do or to use" they are quickly removed from the site by the moderators.
In my opinion, you are right to use the sample template. Also #John Thomas is correct. But you can go beyond:
Use a template for database procedures and functions to work with requests;
Try to put the most of the database logic inside the database using stored procedures and functions. This way you don't have to worry about selecting what is common use and what is specific to current project;
Use a template for main menu and main screen;
Instead of crating many windows, create one TFrame for each module of your application and reserve a place in the main screen to load them. Create an object of this frame in memory only when the user clicks it's menu. This way, your system gets faster and more memory economic;
Reuse those frames by creating base frames with the common functionality and layout and them create new frames descendants from it.
Just great!

Freeware "Structural Highlighting" for Delphi 2007 IDE

I'm in the middle of sorting out a nested set of if/then begin/end pairs, and missing the heck out of CodeRush's structural highlighting (which I used to have in Delphi 6, and loved). Is there a freeware IDE add-in out there that will accomplish the same for Delphi 2007?
Note: I know Castalia does this as well. I tried Castalia a while back, and had trouble w/its stability; also don't really feel like spending $99 at the meoment for just this one feature, (plus maybe the split-editor feature). I may anyway, but thought I'd ask here first to see if there are cheaper alternatives.
Thanks in advance.
cnPack has a feature like this (draws a tree showing the structure)
Step 1: edit the code to simply visually align the nested blocks according to good practice, with consistent indenting etc.
You might be able to use a "pretty printer" to assist in this one-off activity. There are lots of these out there (including one built in to Delphi 2010 these days, as of Delphi 2010, which is no use to you I imagine). I don't know how many of them work on code snippets, rather than relying on complete units however.
Step 2: if the number and level of nested blocks is such that it remains confusing and unclear, refactor to reduce the number and level of nesting.
The result: code that is readable in any medium, without needing to lean on IDE confections which won't always be available to you (e.g. if using SVN and viewing diffs via WebSVN or some other collaborative code review process that doesn't use an IDE with lots of bells and whistles installed).
GExpert is my favorite addin for Delphi. It is free, mature and I use it every day.
Some highlights:
VERY fast search in source. This is so valuable for me.
Convenient find function dialog by typing some characters en the name.
Match parantheses, begin/end, and some other types.
Everything can be handled by a shortcut.
Many other things that I don't use so much at the moment.

Best auto-update component(s) for Delphi

I am re-writing and/or consolidating a bunch of my "app framework" classes (basic mainform, about box, locking routines & purchase linking, auto-update, datamodule initializer, etc) -- Basically, I have a number of small potential shareware apps that I'm wanting to get out the door, and want to re-use code where I can, as well as build a framework for later apps to save time.
In one app I have auto-updating, I'm using LMD's WebUpdate, and am reasonably happy with it, but given that I'm re-vamping everything, I thought I'd see what the consensus is for "best approach" on this. I don't mind paying for commercial, nor using open source if that's best... just would rather not reinvent the wheel. (I've read: Delphi: How do you auto-update your applications?)
What is the best Auto-update component for Delphi Win 32 apps?
I use TmxWebUpdate. It's free, simple and easy to customize. I also own TMS Component Pack with TWebUpdate, but never really found a good incentive to switch.
I use TWebUpdate from TMS Components and am very happy with it. I haven't used LMD so unfortunately am not able to provide a comparison.
TMS also supply a whole raft of other components so if your re-writes require any else, especially if you want some shiny UI enhancements (TMS have a range of iPhone-style components) then the website is certainly worth a visit.
They seem fairly active in their support forums (although I haven't had need to use them for the WebUpdate component) and they have a fairly regular release cycle.
I have heard good compliment about TWebUpdate from Tmssoftware
also torry has much components for the same job, some are free and others are commericals.
Now what's the best?, it's depend on your needs, you already using one from LMD, which is a good company and I have very good experince with their components, but never used this one.
If you need a specific functionality, or you have some problems with the current one you are using, it's will be better to list them, so you will get a better answers, but it's hard to define the best, because every one has different experience and views.
I use TWebUpdate myself. It works, but the docs are a bit limited and it seems a bit buggy sometimes.
I have looked into LMD's (I have their full component pack), but it seemed to be much more limited than TWebupdate.
I'm also using TWebUpdate, and have to echo stg's comments on quality of support (good), and quality of documentation (spotty -- it's old, and doesn't always reflect their new features immediately).
You'll also find some places that stress the "roll your own" approach.
Remember that part of the auto-update issue is the tools that you will need to create the update "package" at your end. TMS Software makes a tool available for use with TWebUpdate, and it's reasonably well done. In my case, I'm "misusing" the component to deal with multiple files so that I can refresh additional related libraries, text files, etc. The update builder tool isn't really good for that. So there's some manual editing. But the updating part works well.
I'll also add a caution that you need to be careful with updates in Vista (and probably Windows 7). Writing to the protected places in the Program Files hierarchy was problematic for me. You may want to check that out with whatever component you use.
Have you considered Appwave from Embarcadero. It's not free and I don't know the price.

Resources