Subject The Python Way
Author Lele Gaifax
Hi all,

I would like to share with you some code I wrote that may be generally
useful. Maybe you already know `Python', maybe not: it's a high-level
object oriented language, very portable and easy to understand. It's
availability on both Un*x and Widows OSes makes it very handy to hide
behind an OO layer the peculiarities of both.

What I'm doing here is to announce some tools I will contribute to the
community, if they prove interesting enough. I'd like to hear
consideration too.

Well, it happens that a complete suite of Delphi components allow a
seemless integration between the to environments: it allows you to
build a Delphi app without using Delphi, or some sort of, since you
have a two way connection between Delphi objects and Python ones. See for details. This
suite already provide the needed code to expose to Python the BDE DB
components, so that you can open and operate on any BDE datasource.

I couldn't resist to the temptation of doing the same on IBO :-) What
is needed is a set of "wrapper" classes, one for each Delphi class
that needs particular exposure: for example, the BDE code exports just
the TField, TTable and TQuery, and not much else. This wrappers are
the interface between the two object systems, and allows you to attach
for example a Python method to the AfterScroll event of a TQuery...

But since I'm lazy, I couldn't code it the way the original author
used for the BDE stuff. I wanted to automate as much as possible the
process... some sort of processor that given a Delphi class could
create the base template.... So I wrote a parser (you guess it, in
Python of course) that is able to extract the usuful info directly
from the IBO sources (or whatever else, for that matter). The code
reads for example the IBA_Column.INT source, that contains the
interface for the TIB_Column class, and builds an internal tree of the
information it contains, such as enumerations, event types, classes,
properties, each with it's documentation, if it's there. On that, I
wrote another script that, for a given class, emits a set of files
that may be $INCLUDEd in the template class source to actually build
the wrapper class for IB_Column, in a way very similar to the one
Jason use in the IBO sources.

As a side effect, the parser can be used to extract and build the
external documentation, maybe translating it from an HTML form into
something more powerful, such as PDF, or better something like the
DocBook, an SGML definition for manuals and documents...

On a completely different front, that eventually says something on the
flexibility of Python itself, I wrote some tools that allowed me port
most of my application from BDE/FIB/IBX to IBO native components. The
existing tools to do it weren't up to the task: I relay havily on form
subclassing, and automatically replacing components from within Delphi
in such condition is not easy, to say the least. So I started from
just-another-funny-parser, this time able to parse, elaborate and emit
a textual Delphi DFM. With this you can for example, given the two
sources of a form `MyForm.pas' and `MyForm.dfm', read it, cycle on
each component of kind "TDBEdit", replace it with say a "TIB_Edit",
maybe adjusting something more, and then write the new DFM and the PAS
under some other name. All this is handled by the Python objects
behind the scenes, you simply state the renaming rules, and eventually
add the code for a particular component: in the upcoming BDE-to-IBO
script for example, it was easy to replace each TDBNavigator with a
TPanel layed down at the same position, containing a IB_NavigationBar
plus a IB_UpdateBar that nicely fits the panel, while keeping the
original DataSource connection :-)

Of course, this just cover the initial part of every port: there are
things that cannot be automated, or are better handled by a human
rather than by a "smart-as-a-rock" script :-) Anyway, I was able to
convert my applicationx, concentrating on the interesting parts, and
saying "the DFMs are almost done!"

That's it for now, I hope this trigger the attention of some body. I
plan to release the above tools RSN, after some needed refiniments.
Let me know what you think!

Thanks for reading so far !-)
bye, and have a nice weekend!
nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri
real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia.
email: lele@... | -- Fortunato Depero, 1929.