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;