23 May 2011

Hide MDI Child Form

Use the ShowWindow function instead:

To hide:

procedure T_mdi_child_form.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  //this resolves problem with maximized MDI active form close

  if Self.WindowState = wsMaximized then Self.WindowState := wsNormal ;

  Action := caNone;
  ShowWindow(self.WindowHandle, SW_HIDE);

end;


To show:

procedure T_mdi_child_form._action_show_Execute(Sender: TObject);
begin
  inherited;
  if _
mdi_child_form = Nil then
     Application.CreateForm(T_
mdi_child_form, _mdi_child_form);

  ShowWindow(_
mdi_child_form.Handle, SW_SHOW);
  _
mdi_child_form.BringToFront ;
end;

13 May 2011

Delphi Uses Cleanup

When you drop a VCL component on a Delphi form the Delphi IDE automatically adds the unit(s) required by the component to the interface section uses statement. If you later remove the component, the units are not removed from the uses statement. This causes the need to sometimes clean the uses statement of unused units.

The Delphi smart linker will ignore unused code so normally the presence of these "extra" units does not increase the size of the compiled program.

I generally copy the default Delphi uses clause

// for TForm
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

// for TDataModule
uses
SysUtils, Classes;

into the unit and comment out the original uses clause (in the interface section). Then I do save and Delphi will add all the units that the components on the form need. Next I add some missing units from commented block like ShellAPI e.t.c., for full compile, without errors.

from http://www.brenemanlabs.com

07 May 2011

PostgreSQL > Restore 9.x backup in 8.x server

If you have a binary formatted dump file.backup, from some unknown PostgreSQL server 9.x version, and need to be restored to an older server running a 8.x version, when you try to restore it, you would got an error:

$ pg_restore -d rc -Fc dump.backup

pg_restore: [archiver] unsupported version (1.12) in file header

$ pg_restore --version

pg_restore (PostgreSQL) 8.3.13

So you probably have a version mismatch, but what where does it get 1.12 from? After some googling I found that 1.12 actually means 9.0 (naturally), so I used the 9.0 version of pg_restore to convert my binary file into a plan SQL file via the -f parameter.

$ pg_restore --version


pg_restore (PostgreSQL) 9.0.3

$ pg_restore -Fc dump.backup -f dump.sql

Copy dump.sql back to 8.3 server

$ psql database -f dump.sql


If you have some functions in that backup, you need to put these statment in start of dumped sql file :

CREATE LANGUAGE plpgsql;

Now everything shold work fine.

06 May 2011

Lazarus > PostgreSQL > Post data

To post data in PostgreSQL database, even after active session, using standard Lazarus IDE TPQConnection control, create event :

procedure T_c_data._sql_tableAfterPost(DataSet: TDataSet);
begin
  _sql_table.ApplyUpdates;
  _db_transaction.Commit/Retaining;
end;

25 April 2011

PostgreSQL Backup and Restore

To backup and restore PostgreSQL with ignoring of database version us pg_dump and pg_restore like in next commands:

For Backup :

C:\pgsql\bin\pg_dump.exe
--host localhost
--port 5432
--username "username"
--format custom
--blobs
--ignore-version
--verbose
--file "postgresql.backup" databasename

For Restore :

C:\pgsql\bin\pg_restore.exe
--host localhost
--port 5432
--username username
--dbname databasename
--clean
--ignore-version
--verbose "postgresql.backup"

20 April 2011

How to change encoding type

Dump your database, drop your database, recreate your database with the 
different encoding, reload your data.  Make sure the client encoding is 
set correctly during all this.
 
P.S.: 
CREATE DATABASE test
  WITH OWNER = postgres
       ENCODING = 'WIN1250'
       TABLESPACE = pg_default
       LC_COLLATE = 'Serbian (Latin)_Serbia.1250'
       LC_CTYPE = 'Serbian (Latin)_Serbia.1250'
       CONNECTION LIMIT = -1;

25 December 2010

Lazarus, PostgreSQL, Fortes report - Bytea String BLOB fields

To save some image into dbimage control on a form :

procedure T_form._dbimageDblClick(Sender: TObject);
begin
if _opendialog.Execute then
begin
_db_grid.DataSource.DataSet.Edit;
_dbimage.Picture.LoadFromFile(_opendialog.FileName) ;
end;
end;

To print those fields in Fortes report, use dbimage >

procedure T_report._rlimageBeforePrint(Sender: TObject; var PrintIt: boolean);
var
st : Tstream;
s : string;
gc : TGraphicClass;
AGraphic : TGraphic;

begin
gc := nil;
AGraphic := nil;

st := _datamodule._table.CreateBlobStream(_datamodule._table_image_field,bmRead);
s := st.ReadAnsiString;

try
gc := GetGraphicClassForFileExtension(s);
if assigned(gc) then // gc is never assigned
begin
AGraphic := gc.Create; // never executed
AGraphic.LoadFromStream(st); // never executed
_rlimage.Picture.Assign(AGraphic); // never executed
end;
finally
if assigned(AGraphic) then
AGraphic.Free;
st.Free;
end
end;

I spend whole day just to develop those code ...

09 November 2010

Fedora pgAdmin3

If you get error while loading shared libraries: libssl.so.0.9.8 in fedora while start pgadmin3

you have to make symlinks

sudo ln -s /lib/libssl.so.0.9.8b /lib/libssl.so.0.9.8
sudo ln -s /lib/libcrypto.so.0.9.8b /lib/libcrypto.so.0.9.8

31 October 2010

Dynamic libraries can be found: libpq.so.4, libpq.so

I'm investigating the use of lazarus/postgresql for a linux desktop application.

Fresh Linux installation produce this error, when starting application

Sender=Exception
Exception=None of the dynamic libraries can be found: libpq.so.4, libpq.so

Fix is

ln -s /usr/lib/libpq.so.5 /usr/lib/libpq.so

18 October 2010

Lazarus Report Preview

This is a main logic of sample code to produce Preview of LazReport :

procedure T_f_main._ButtonClick(Sender: TObject);
begin
_frReport.LoadFromFile('_izvestaj.lrf');
_frReport.ShowReport;
end;

Lazarus ZeosDBO Stored Procedure Call for PostgreSQL functions

This is main logic in some Lazarus database form, powered by ZeosDBO, to call stored procedure (postgresql function), who is placed in ZSQLReadOnly SQL property, like

SELECT * FROM Name_Of_Function()

Then In ZTable BeforePost event, you reopen that ZSQL to retrieve default value of primary key, like this code :

procedure T_f_main._ZTableBeforePost(DataSet: TDataSet);
begin
if _DataSource.State in [dsInsert] then
with _ZSQL_readonly_procedure do
begin
Open ;
_ZTableID.Value := Fields[0].asInteger;
Close ;
end;
end;

16 October 2010

postgresql on OpenSuse default login error (solved)

On terminal test : psql -h 127.0.0.1 -p 5432 postgres postgres

If you receive error:
psql: FATAL: Ident authentication failed for user "postgres"

Edit /var/lib/pgsql/data/pg_hba.conf, and write

trust

instead of "ident"

then reload PostgreSQL

As root: service postgresql reload
or as postgres user: pg_ctl reload

Ownership of pg_hba.conf has nothing to do with the authentication.

14 October 2010

Is Lazarus ready for writing commercial applications ?


(this is one software developer experience from Blaise Pascal Newsletter , that proves that Delphi multiplatform magic is possible, but in Open Source world through Lazarus project, so I simply must share it on my blog...)

"This article illustrates the enormous progress Lazarus has made because of the dedicated work of the core developer team: it shows Nowadays Lazarus is in many ways on a par with Delphi. In several key areas it is way ahead of Delphi (64 bit compiled executables, multi-platform and multi-OS, allows development on mobile and embedded systems).

Of course it is not the same as Delphi, but very cheap - see the price of the Lazarus USB stick in the Advertisement. So affordable for anyone and you get started immediately with no installation required. You can create any application you ever wanted and the number of components available is grows steadily. So the answer is YES. Perfect for commercial applications!

I started my job in 2001 at a Croatian company called Holobit...

At that time Holobit was a pretty small company with a few dozen customers. My primary task was to make the company's current C++ business applications run on Linux and Windows by using Delphi and Kylix and Borland's CLX technology. After years of C/C++ coding on linux OOP looked very simple and well organized. Two months later I concluded that Borland had great products, and the coding time is much shorter than it was with C/C++ (gtk+,qt) using vi editor. Anyway, within 3 months our business applications were converted to CLX and the company started selling for Linux & Win32. All was done with Kylix 2 and Delphi 6 (later upgraded to K3 & D7).

Creating native Linux apps was a good decision, so the number of customers started growing rapidly. Our customers were happy with the ability to choose between Linux and Windows client apps for dekstop PC’s, because it saves some money and creates a better and more secure environment. The second conversion issue that looked rather complicated - at that time - were databases. When I started to convert our applications, all of them used Foxpro, and I was very disapointed with it, because I already used Postgresql on Linux. So your guess that we moved all of our applications to Postgresql is quite correct.

At that time I didn't know third party components like Zeos etc..., so I wrote my own Postgresql driver and used it for several years. Later when I found Zeos - a nice surprise – I immediately started to use that. So it went on until 2004, there were rumors that Kylix was Exit, no news from Borland – just silence ... Yes it was Exited: shame on you Borland, not because you put Kylix into grave, but because you cheated your customers. For years, then, we were fighting with Borland products. (In the meantime Kylix could not run on any distributions based on Glibc higher than 2.4.X) then, until I saw someone had started a qt-widgetset in a Lazarus project, and that guy was Felipe, and thanks to Den Jean for Qt C bindings, because without C bindings we could not have a Qtwidgetset inside Lazarus.

I had looked into Lazarus just a few times before, but I was not attracted previously, because it supported only the Gtk1 widgetset which looked awful compared to the Qt2 used by Kylix, so now I got motivated to download the lazarus trunk and find out to see the way how it worked with Qt. (I already tried Gtk before). Well, as IG mentioned already, work on the Qt widgetset having only just started, the result needed a lot of improvements, so it does not work.

After a quick scan of Lazarus principles, the Lazarus component library (LCL) and widgetset connections to the LCL I began to contribute to the Lazarus project with a primary goal to get Qt widgetset up and running. My first patches then were sent to Felipe. He argued about my coding standards (hey, hey), but I fixed that and changed my coding standards to the Lazarus coding standard. Anyway, after a year or so the Qt widgetset became useable - in the meantime Lazarus developers granted me svn write access - so no more need to wait for Felipe and others to commit my patches. At the same time – business problems arose with Kylix & Delphi programming and the company management considered moving our thought about to move the complete codebase to Java or .Net . When the management decided this change must be made quickly I objected.

I was not very happy with that. Not because of the applications, but because of all the third party components used in our applications (ZeosLib, FastReports, TMS grids, VirtualTrees etc). I said that we would need a lot of time and resources to move our code to Java or .Net and the result of that operation was not reassuring. I was disturbed by these business decisions (and already had in mind to change the job), so at one day I asked the chief if they could agree to let me spend some time developing code using Lazarus, and in the next few months I showed some of our apps running on Qt4.

I had started a race against time, I had to fix the Qt-LCL and convert one of our applications to LCL (only a small one). That wasn't an easy task since qt-lcl is still not finished and lot of things were not working. Zeos for Lazarus already existed, but for this simple applications I had to have FastReports and TMS grids. So I had three months to make Qt under Lazarus useable, convert FastReports and TMS grids (both CLX licensed)...

After hundreds of hours of coding, the day of reckoning came. I had to show my work at the end of February 2008. I made a presentation on Linux, 32 bit Windows and on Mac OSX and the company management was pleased and satisfied with it. Of course there were still bugs and features not yet implemented, but they appreciated my main argument. If we moved to Lazarus we would be able to work on other (even more) supported platforms, and also because Lazarus is an open source project, we would not be at the mercy of decisions made by other companies (such as Borland) that had harmed us in the past. That became the happiest day in the last few years of my working life. I was given the budget and time required to move our applications to Lazarus. Now I had a reasonable time (15 months) to improve Lazarus and re-write our applications for Lazarus (and deal with other everyday tasks). During 2008/2009 I converted all the third party components and all of our applications to FPC/Lazarus, and therefore also contributed a lot of patches to the Lazarus project. The Goal is reached – Lazarus is better now than Kylix 3 and we started to deploy Lcl LCL applications over more than 3,500 at customers’ sites.

User impressions were positive since our apps looks native on all platforms. A few dozen of Mac OSX users were also happy since we give them native apps for the first time (they used Parallels + linux VM). WOW, what a glorious day. We just did not need the Borland products anymore.

Now our complete range of software is developed using FPC/Lazarus and uses PostgreSQL RDBMS:
1. HoloERP – ERP system with > 400 modules (forms)
2. Cafeman – Caffe bars & restaurants backoffice and POS system
3. TSuS – small shops backoffice & POS system
4. Cinema – software for cinemas (reservations, tickets etc)
5. ArhStudio – architects documentation database.

All of those these applications use the following 3rd party components:
· ZeosLib
· FastReports (ported CLX)
· TMS Grids (ported CLX, but also we licensed the newest VCL
and ported it also)
· TMS Planner (ported CLX, later VCL)
· FlexCell (licensed LCL , yes there's LCL version)
· Our custom components

Conclusion:
Why?
Lazarus is ready for commercial usage especially for people with legacy Kylix3 / Delphi7 codebases.
My personal opinion is that Lazarus Qt is much better than K3/D7 at this time (0.9.29 trunk), and developers will be happy with it's new 0.9.30 version.
· The only OOP RAD which supports so many platforms.
· Constantly developed by volunteers, it does not depend on commercial decisions so you can avoid bankrupcy etc.
· Costs almost nothing except energy and time.
· If it doesn't fit your needs, you can change it and contribute.
· If there's a bug - you can fix it and contribute it, but at least you can open an issue at lazarus mantis issue tracker."

Author of this blog text is Lazarus forum member Zeljan and software case is from http://www.holobit.net

02 October 2010

MS Windows Mobile 6.5 - How to return default lock screen

To return default lock screen in MS Windows Mobile 6.5 in some cooked ROM (NRG, TAEL and other), you should remove these registry keys :

[HKEY_LOCAL_MACHINE\Security\Shell\Lock]
"CustomLockScreensMask"=dword:00000013
"CustomLockScreensPath"="\\Windows\\LockScreen"

29 September 2010

How to import Google Earth POI.KML file into IGO8

POI (from POIplaza)

1 Turn off the write protection of the Dreimgo Memory Card.
2 Connect the memory card or the navigation device to PC,
then create the following path on the memory card: igo8/content/userdata/POI.
3 Download, unzip and copy the the downloaded .kml files to the above map.
4 Restart your navigation device.
5 Run the navigation software and swich to Advanced mode. Choose the Manage POI icon.
6 Choose downloaded POIs (kml file); then choose Edit and set the distance of POI icon visibility.
The default icon is Google Earth’s globe.
7 In the Navigation menu choose Find POI, and choose as Destination.

Note: some POIs might not be reachable on the map, if the map is not detailed enough.

Speedcam iGO8

1 Download as speedcam the iGO8_txt.zip file to a folder on your PC.
2 Unzip the two files, speedcam.txt and POIplaza-iG08 Notes.txt.
3 Copy the speedcam.txt file to the Storage card/igo8/content/speedcam.
4 Restart iGO8, the file will automatically update the database.
5 There will now be three files in the speedcam directory, speedcam.spdb, speedcam.txt and SpeedcamUpdates.spud.
6 Allow the device to detect a GPS signal. When this is done the speedcam locations will be active.
7 Check Settings/Warnings has Speed Camera Warning enabled.

Note: conversion of speedcam files is time consuming especially in case of a large file.
During conversion an 'init warning messages' message is visible.

18 September 2010

pgtray - PostgreSQL Tray Monitor

In working with the PostgreSQL server, there is no Tray Monitor, as in the MySQL database server. I searched the Internet, but such a project in pgFoundry is very outdated and in version 1.0. I thought I'd make this little tool on my own, and here's how it looks ...



You can download it here.

17 September 2010

PostgreSQL - Manual (silent) instalation

PostgreSQL - Manual (silent) instalation
1) Download postgresql-*.*.zip.
Here we’ll use c:\pgsql as the target directory, so
2) Extract the archive to that directory.
Go to that folder and type in command prompt
3) initdb c:\pgsql\data
4) pg_ctl register -N postgres -D c:\pgsql\data
5) net start postgres
net user postgres postgres /add /expires:never
6) createdb database_name
or
createdb -E unicode --template template0 database_name
7) createuser -d -s user_name (postgres)
8) psql -U user_name -d database_name -f file.backup
and then, if needed
or
pg_restore --host localhost --port 5432 --username postgres --dbname database_name --verbose file.sql
9) pg_ctl unregister -N postgres

Change database encoding to UTF-8

vacuumdb --full --analyze --username postgres --dbname MYDB
pg_dump MYDB -Ft -v -U postgres -f tmp/MYDB.tar
dropdb MYDB --username postgres
createdb --encoding UNICODE MYDB --username postgres
pg_restore tmp/MYDB.tar | psql --dbname MYDB --username postgres
vacuumdb --full --analyze --username postgres --dbname MYDB

31 August 2010

Exchange Activesync support in Hotmail

Microsoft has made Exchange Activesync support in Hotmail official, meaning according to Microsoft, 300 million mobile devices will be able to take advantage of direct push support from the web mail service.

The settings to enable to service on compatible devices (which does not fully include Android devices yet) are:

Server / URL
m.hotmail.com

Username
Enter full email address, for example: someone@example.com

Domain
Leave this blank

SSL
Enable this

Certificate
Accept the SSL certificate when prompted

Mail, Contacts, Calendar, Tasks
All can be enabled (see the Solution Center article for exceptions on some phones)

Windows Mobile users who do not have an existing Exchange Activesync account will not be able to benefit from a free hosted exchange solution without using Microsoft’s Windows Live client, while of course Windows Phone 7 users will be able to use multiple Exchange accounts directly

27 August 2010

ACC97: Error: "There Isn't Enough Disk Space or Memory"

Method 1: Set the registry key to MaxLocksPerFile to increase the maximum number of locks per file

1. Click Start, and then click Run.
2. Type regedit, and then click OK.
3. Use the appropriate method:
* In Microsoft Access 2000, in Microsoft Access 2002, and in Microsoft Office Access 2003 that are running on a 32-bit Windows operating system, use Registry Editor to locate the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Jet 4.0

In Microsoft Access 2000, in Microsoft Access 2002, and in Microsoft Office Access 2003 that are running on a 64-bit Windows operating system, use Registry Editor to locate the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\Jet 4.0
* In Microsoft Office Access 2007 that is running on a 32-bit Windows operating system, use Registry Editor to locate the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Access Connectivity Engine\Engines\ACE

In Microsoft Office Access 2007 that is running on a 64-bit Windows operating system, use Registry Editor to locate the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Access Connectivity Engine\Engines\ACE
4. In the right pane of Registry Editor, double click MaxLocksPerFile.
5. On the Edit DWORD Value dialog box, click Decimal.
6. Modify the value of the Value data box as required, and then click OK.

Note This method changes the Windows registry setting for all applications that use the Microsoft Jet database engine version 4.0.

26 August 2010

Enable only Wifi Internet on HTC Windows Mobile

start->settings->connections->connections

Mobtel Telenor Internet
My Work Network

Go to advanced->select My Wok Network [the first button over composition rules]

Here select "work" for everything.

Now, without 3G, the phone connects to internet only if you have an active wifi, otherways doesn't connect.