Pascal Newsletter - Delphi+mysql
Pascal Newsletter - Delphi+mysql
INDEX
________________________________________________________________________
Those of you who follow the Developers Newsletter probably have read
that -due to work reasons- that newsletter will go monthly.
Nevertheless, I'll strive to keep releasing the Pascal Newsletter more
or less twice a month as I've been doing so far, though I would really
appreciate some help.
You can help keep this newsletter going by contributing articles about
Delphi programming. You will retain the copyright of all the material
you submit to us, but you should grant us a permanent non-revocable
royalty-free permission to translate and publish your article (in its
original form and translated) as long as we do it in full (including
your copyright notice and author information you submit to us for the
purpose of being published, like email address, web site, educational
institution, etc.), without modifications and free of charge. The
newsletters are published by email and at our web site, and each issue
is licensed to be copied and reproduced by anyone as long as it is done
in full (including copyright notices and authors' information), without
modifications and free of charge. If you don't agree to these terms, we
can talk about publishing your articles in our web site (not in a
newsletter) under your own licensing terms.
TAKE THIS OPPORTUNITY TO STAND OUT FROM YOUR COLLEAGUES AND TO ADD A
PUBLISHED ARTICLE TO YOUR CURRICULUM VITAE. WE GIVE CERTIFICATES.
By the way, in this issue I'm glad to present the first contributed
article, which has also been published in our web site:
Changing subjects, there are a couple of new Delphi tips in our web
site:
Ernesto De Spirito
eds2004 @ latiumsoftware.com
________________________________________________________________________
2. MYSQL
WHAT IS MYSQL?
==============
MYSQL LICENSE
=============
MySQL is licensed under the terms of the GNU General Public License. It
is free for internal use and for ISPs. For example it is free if you use
it for software development or for companies that may use it as a
database server, and it is also free if you develop a tailor-made
application for a client (it is still considered internal use for both
parties).
A single license costs $200 (USD), and you can buy many licenses
before actually using them to take advantage of important discount
prices.
You can distribute a non GPL application that uses MySQL without paying
a license if the use of MySQL is not required (i.e. if the application
can alternatively do the same stuff using another database system,
server, driver or whatever).
DELPHI AND MYSQL
================
ODBC
----
In the MySQL web site you can find the MySQL ODBC driver for Windows:
http://www.mysql.com/downloads/api-myodbc.html
After installing this driver you can use the BDE Data Access components
or the ADO components to access tables or to perform queries on a MySQL
database.
To use ODBC, first you should create a DSN using the ODBC Data Sources
applet of the Control Panel. For example, I created a DSN named
MySQL_Test and configured it to log in as 'root' in the MySQL server
located at 'localhost' (you can connect to a remote server using its IP
address or its domain name) and open the 'mysql' database.
AliasName = 'MySQL_Test'
DatabaseName = 'MySQL_Test'
LoginPrompt = False
The advantage of using ODBC is that you can use the standard Borland
Datasets, and the disadvantage is that you have to go thru two layers to
get to the MySQL server (the BDE and the ODBC driver), although it must
be said that even with ODBC, MySQL is still faster than other database
servers.
LIBMYSQL.DLL
------------
You can also access a MySQL server using the libmysql.dll library. This
file doesn't come with the standard MySQL installation, but you can
download it from:
http://www.fichtner.net/delphi/mysql.delphi.phtml
You should also download the mysql.pas file which is a Delphi a unit
that contains the type declarations for using this library. You need to
include this unit in the uses clause of any unit from which you want to
call the functions contained in the library.
As you can see, it's quite complicated, and this constitutes the main
(and I would say only, but very important) disadvantage of using the
libmysql.dll library. The advantages are that you have full control,
that it's faster than using ODBC, and that it doesn't requiere the BDE.
It would be nice to have a TDataset descendant that encapsulates the
libmysql.dll API...
WINZEOS
-------
http://www.zeos.dn.ua
The package is distributed under the terms of the GNU General Public
License, but as we explained you can use it freely for "internal use",
including the development of tailor-made applications.
________________________________________________________________________
Four are the fundamental facts in the present essay: The first of them
is the existence of programs that mimic Post-it (those little sticky
pages that come in notebooks and flood offices with flashy colors).
Second, the use of certain undocumented Windows function to drag forms.
Third, the problem of how to create an application where the main form
is not visible. And fourth, using the Windows task bar.
The programs that mimic Post-it I take as reference are mainly TurboNote
in Windows and the one of KDE in Linux. Both programs are easily
acquirable and do more than the one I present here. However, I consider
this a good teaching example.
The obvious is to imitate a post-it note in some way. The first thought
is a form with a title bar without the usual buttons (minimize,
maximize, etc.) and completely with a plain color. This alternative is
possible and requires a bit specialized Windows management. In
particular I have chosen a more economic alternative regarding code (or
at least that's what I think); and this is eliminating the title bar and
form borders (like you would do in a "splash-screen") and place a panel
and a memo in a form, the first aligned to top and the second to the
client area.
The form with just a panel and a memo will respond without problems to
keyboard actions, but it is obvious it won't respond to mouse drags and
size changes with the mouse (without borders from where to hold it). The
drag is resolved with an undocumented action, at least that's how it was
some time ago, thru the message SysCommand. The line shown here,
executed from a form, places it in drag state.
Perform(wm_SysCommand, $f012, 0)
The matter with the messages doesn't get limited to this. The resize
modes are also defined that way. For this purpose we defined a set of
constants with the appropriate values starting from $f012.
sc_DragMove = $f012;
sc_Leftsize = $f001;
sc_Rightsize = $f002;
sc_Upsize = $f003;
sc_UpLeftsize = $f004;
sc_UpRightsize = $f005;
sc_Dnsize = $f006;
sc_DnLeftsize = $f007;
sc_DnRightsize = $f008;
NOTE: If you wonder where these values came from, well, what can I
say... I got to know the first one by a Marco Cantú book called "Delphi
Developers' Handbook", the rest came out from trial and error. Let me
tell you that $f040 produces a disastrous result. Also $f020 and $f030
minimize and maximize respectively, which is not necessary for our
application. I don't know if any of this works outside Windows 98.
Additionally, in the MouseDown event of the panel and the memo, where we
send the messages, it is necessary to call ReleaseCapture before sending
the indicated messages.
I won't extend much with the code. It's easier to analyze it from Delphi
than from an HTML page or a DOC. But notice that it has to be
distinguished where a click happened in the panel to know if it is
required to resize or just drag the form. Something similar happens with
the memo for the resize of the bottom and lateral sides.
procedure TfrmNota.Panel1MouseDown(
Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
if y<2 then
begin
if x<4 then
Perform(wm_SysCommand, sc_UpLeftsize, 0)
else if x>(Panel1.ClientWidth-4) then
Perform(wm_SysCommand, sc_UpRightsize, 0)
else
Perform(wm_SysCommand, sc_UpSize, 0)
end
else
Perform(wm_SysCommand, sc_DragMove, 0)
end;
sources are part of this article and you will be able to see the
note working in detail. In the attached example, apart from the mouse
event handling we make use of the Windows Registry to store information
relative to the note itself (like its position, font type and color). I
presume that if you understand what we have done up to this point, you
don't need explanations about the use of the Windows Registry (anyway,
its use seems to be well documented in the Delphi Help, and there are
examples and information about it in the Internet).
When I made this program I hadn't though of a really silly problem. The
user shall be able to create and destroy notes, but he can't destroy the
main form because this finishes the application. Well, then simply with
not showing the main form it should suffice. If you want to understand
this silly problem create an application in which apart from the main
there exists a secondary form; then make the application start showing
only the secondary form. My attempts resulted in failure. Now I know
this gets accomplished with
Application.ShowMainForm := False;
in the main program before creating the forms, but back then I didn't
know it and I took advantage of the problem to give it an original
solution...
IT'S NOT A BUG, IT'S A FEATURE
==============================
Thinking around the matter, the solution was converting the main form in
a splash screen that lasts a certain amount of time and then hides. This
code gets executed in a timer:
With this, the main form gets hidden (the next line right after the
assignment of the "oculto" (hidden) variable, that by the way is False),
and also the presence of the application in the task bar.
The rest of the code is relatively simple and contains some routines to
save and restore the content and configuration of the notes (the first
to disk and the second to the Registry). I believe it doesn't deserve a
deep discussion and therefore I leave to the reader the interpretation
of the routine.
POP-UP MENU
===========
The application doesn't have a main menu because it doesn't have a main
form. All actions different than interaction with the memo field and
mouse movements are done by pop-up menus. There are two: one in the note
and one in the icon of the task bar (next to the clock). For this one we
used the RX. Therefore at least for this version you will need to have
sources. If you don't know them, them you should do it, they are free
("freeware") and very good.
The source code that accompanies this article can be downloaded from:
http://www.latiumsoftware.com/download/h-notes.zip
________________________________________________________________________
4. LINKS
________________________________________________________________________
We need your help to keep this newsletter going and growing. You can
help by referring the newsletter to your colleagues:
http://www.latiumsoftware.com/en/pascal/delphi-newsletter.php
http://www.sandbrooksoftware.com/cgi-bin/TopSite2/rankem.cgi?id=latium
http://news.optimax.com/delphi/links/links.exe/click?id=70C517ECAE6E
http://www.programmingpages.com/?r=latiumsoftwarecomenpascal
http://www.top219.org/cgi-bin/vote.cgi?delphi&83
http://top100borland.com/in.php?who=20
http://top200.jazarsoft.com/delphi/rank.php3?id=latium
http://213.65.224.200/cgi-bin/toplist.cgi/hits?Id=80
It's just a few seconds for you that REALLY mean a lot to us.
________________________________________________________________________
If you haven't received the full source code examples for this issue,
you can get them from http://www.latiumsoftware.com/download/p0010.zip
________________________________________________________________________
This newsletter is provided "AS IS" without warranty of any kind. Its
use implies the acceptance of our licensing terms and disclaimer of
warranty you can read at http://www.latiumsoftware.com/en/legal.php
where you will also find a note about legal trademarks. Articles are
copyright of their respective authors and they are reproduced here with
their permission. You can redistribute this newsletter as long as you do
it in full (including copyright notices), without changes, and gratis.
________________________________________________________________________