Archive for the ‘Delphi’ Category

Great Delphi Page

Saturday, March 27th, 2010

f you are looking for an interesting page that explains how to do some of the more difficult things in Delphi, Pipes, Sockets, etc visit Felix Colobri’s site.

Not only does it provide source code to examine, his teaching background makes what he says understandable.

http://www.felix-colibri.com/index.html

Even if you don’t use Delphi, his site will give you some insight on many programming topics, no matter what language you program in.

Filter on a TClientDataSet

Saturday, March 14th, 2009

Filtering on a TClientDataSet is very powerful.

For the longest time I had assumed that there was no way to filter on a field that had a field name with a space in it!

I would try the following:

Table1.Filter:= ‘My field = ‘ + #39 + ‘looking for’ + #39;

And Delphi would squawk that the field ‘My’ did not exist.

I tried to place quotes around the field name. No error occurred, but the filter did not work.

After a long search I came upon a poorly documented fact that square brackets around the field name work in the TClientDataSet filter!

Table1.Filter := ‘[My field] =’ + #39 + ‘looking for’ + #39;
Table1.Filtered := True;

Bring your Application to the top of the screen in Windows

Thursday, March 12th, 2009

I program in Delphi for the Windows environment, but the following should work in most modern programming languages with slight modifications.

Since Windows 98, the standard BringToFront() function no longer has the same power. When called, your application’s window remains where in is in the z-order, and the task button flashes.

I was asked to make our Emojic Text Editor have a Stay On Top feature.

The following event routine for a CheckBox was created:

procedure TMainForm.StayOnTopClick(Sender: TObject);
begin
Application.NormalizeTopMosts;
If StayOnTop.Checked then
begin
SetWindowPos(MainForm.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
end
else
SetWindowPos(MainForm.Handle, HWND_NOTOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
end;

That worked great until my application tried to save and open it’s own Modal Form. Then my Modal Form was locked away and inaccessible under my Topmost window.

So I placed the following around every set of instructions in each of my MenuItem’s Event routines:

procedure TMainForm.SaveMenuItemClick(Sender: TObject);
begin
SetWindowPos(MainForm.Handle, HWND_NOTOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
SaveFile;
StayOnTopClick(self);
end;

Basically I just turn the Stay On Top feature off until the Event is done, then I check to see if I intend to set the Stay On Top feature back on.