INDODELPHI

Blog’s Tutorial Delphi – Reference from Onez Delphi Explorer

IS THE TASKBAR ALLWAYS ON TOP?

// ******************************************************************
// IS THE TASKBAR ALLWAYS ON TOP?
// Category        : Task
// Author          : ZieglerSoft
// Author Email    :
// Author Web      : http://www.zieglersoft.dk/includes/usercount.asp
// Tips Website    : DelphiTips.com
// Tips Website URL: http://www.delphitips.com
// ******************************************************************

Uses
ShellApi;

Function IsTaksBarAllwaysOnTop:Boolean;
Var
AB : TAppBarData;
Begin
AB.cbSize := sizeof(AB);
Result :=(SHAppBarMessage(ABM_GETSTATE, AB)and ABS_ALWAYSONTOP) > 0;
End;

November 6, 2007 Posted by Musriah | Application - Task | | No Comments Yet

CHANGING AN APPLICATIONS ICON

// ******************************************************************
// CHANGING AN APPLICATIONS ICON
// Category        : Application – Others
// Author          : Rachel and Tracy
// Author Email    : tracy@specialady.com
// Author Web      : http://www.specialady.com/TandR/index.html
// Tips Website    : Rachel and Tracy Delphi Tips
// Tips Website URL: http://www.specialady.com/TandR/index.html
// ******************************************************************

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog.Execute then
begin
Application.Icon.LoadFromFile(OpenDialog.FileName);
end;
end;

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

CHANGE THE DISPLAY TIME OF HINTS

// ******************************************************************
// CHANGE THE DISPLAY TIME OF HINTS
// Category : Application – Others
// Author : Simon Grossenbacher
// Author Email : webmaster@swissdelphicenter.ch
// Author Web : http://www.swissdelphicenter.ch
// Tips Website : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

procedure TForm1.Button1Click(Sender: TObject);
begin
//default = 2500 ms
Application.HintHidePause:=10000 //10 Sec
end;

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

CHANGE APPLICATION ICON AT RUNTIME

// ******************************************************************
// CHANGE APPLICATION ICON AT RUNTIME
// Category        : Application – Others
// Author          : Greatis Software
// Author Email    :
// Author Web      : www.greatissoftware.com
// Tips Website    : Greatis Software
// Tips Website URL: http://www.greatis.com/delphi/tips.html
// ******************************************************************

// Use Icon property of Application object.

Application.Icon.LoadFromFile(‘C:\MyIcon.ico’);

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

CHANGE A HINT’S FONT

// ******************************************************************
// CHANGE A HINT’S FONT
// Category        : Application – Others
// Author          : Simon Grossenbacher
// Author Email    : webmaster@swissdelphicenter.ch
// Author Web      : http://www.swissdelphicenter.ch
// Tips Website    : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

{
When the application displays a Help Hint, it creates an instance of
HintWindowClass to represent the window used for displaying the hint.
Applications can customize this window by creating a descendant of
THintWindow and assigning it to the HintWindowClass variable at application
startup.
}

type
TMyHintWindow = class(THintWindow)
constructor Create(AOwner: TComponent); override;
end;

implementation

{….}

constructor TMyHintWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with Canvas.Font do
begin
Name := ‘Arial’;
Size := Size + 5;
Style := [fsBold];
end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWindow;
Application.ShowHint := False;
Application.ShowHint := True;
end;

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

AVOIDING APPLICATION.PROCESSMESSAGES

// ******************************************************************
// AVOIDING APPLICATION.PROCESSMESSAGES
// Category        : Application – Others
// Author          : DelphiFAQ.com
// Author Email    : tips@delphifaq.com
// Author Web      : http://www.delphifaq.com
// Tips Website    : Delphi FAQ
// Tips Website URL: http://www.delphifaq.com
// ******************************************************************

{
Q:
I am writing a procedure, which may take a long time to execute. I want the user
to be able to stop it at any point of execution. I can use
Application.ProcessMessages to handle a click of the ‘STOP’ button. I also thougt
about creating a new thread for the procedure.
In either case I have to check for a variable ‘ProcedureStopped’ (with
Application.ProcessMessages) or I have to check for MyThread.Terminated.

Both of these require frequent polling. I’d prefer some kind of interrupt to
exit the procedure.

A:
By Hallvard Vassbotn, hallvard@millionhandshakes.com :

Unfortunately, by default the VCL does not have a very thread-friendly mainthread
message loop. It is possible to override the message loop by hooking
Application.OnIdle and call MsgWaitForMultipleObjects there.

Doing this you can build your own multithread aware message loop and thus easiliy
get notified of events and other signals raised from secondary threads.

I wrote an article about this in The Delphi Magazine, issue 40. Even if you don’t
subscribe, you can download the code at
http://www.itecuk.com/delmag/dmdisk.htm

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

APPLICATION.TERMINATE OR HALT()

// ******************************************************************
// APPLICATION.TERMINATE OR HALT()
// Category        : Application – Others
// Author          : DelphiFAQ.com
// Author Email    : tips@delphifaq.com
// Author Web      : http://www.delphifaq.com
// Tips Website    : Delphi FAQ
// Tips Website URL: http://www.delphifaq.com
// ******************************************************************

{
Q:
Should I use Application.Terminate or Halt() ?
And what are the differences?

A:
Application.Terminate closes the main window and that way the application in a
clean fashion. Halt() shuts down right away, e.g. memory may not be freed, tables
are not closed and so on.

For D4: Halt can cause AV’s on an NT system, usually with Runtime error 216, if
DLL’s are involved also 217 – Application.Terminate on the other hand cleans
without AV.
But: Halt worked with D2, even the cleaning of the memory did work….

Then again, if you write a console application, you have to use halt(), since
there probably is no Application object.
}

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

APPLICATION TO BE SINGLED INSTANCE

// ******************************************************************
// APPLICATION TO BE SINGLED INSTANCE
// Category        : Application – Others
// Author          : Damien Thouvenin
// Author Email    :
// Author Web      : http://perso.wanadoo.fr/ali-baba
// Tips Website    : Ali Baba Delphi Tips
// Tips Website URL: http://perso.wanadoo.fr/ali-baba
// ******************************************************************

{
Here is a function proposed by Brendan Delumpa on the Internet that, when
called by a program, checks if there is already another instance running and
then reactivates it. It returns TRUE if there
is another instance. (Brendan Delumpa : http://webx.best.com/~bdelumpa/ )
}

function IsPrevInst: Boolean;
var
semName,
appClass: PChar;
hSem    : THandle;
hWndMe  : HWnd;
appTitle: Array[0..MAX_PATH] of Char;
begin
// Initializations
Result := FALSE;
GetMem(semName,15);
GetMem(appClass,15);
StrPCopy(semName,’SemaphoreName’);
StrPCopy(appClass,’TApplication’);
StrPCopy(appTitle,ExtractFileName(Application.Title));
// Lets create a semaphore. If this is the first instance, hSem will contain 0.
hSem := CreateSemaphore(nil,0,1,semName);
// Does the semaphore already exist ? Yes : second instance.
if (hSem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS) then
begin
CloseHandle(hSem);
// Lets change our main window title in order to find the first instance’s one.
hWndMe := FindWindow(appClass,appTitle);
SetWindowText(hWndMe,’ZZZZZZZ’);

// Then we find the preceeding instance’s main window, reactivate it and
// bring it on front. It isfound by looking for the application’s class and title.
hWndMe := FindWindow(appClass,appTitle);
if (hWndMe <> 0) then
begin
BringWindowToTop(hWndMe);
ShowWindow(hWndMe,SW_SHOWNORMAL);
end;
Result := TRUE;
end;
// Deallocate used Data
FreeMem(semName,15);
FreeMem(appClass,15);
end;

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

AN EXAMPLE OF A SHAREWARE LOCK ON PROGRAM

// ******************************************************************
// AN EXAMPLE OF A SHAREWARE LOCK ON PROGRAM
// Category        : Application – Others
// Author          : Oleg Zavgorodnij
// Author Email    :
// Author Web      : http://www.delphicollection.com/public/Tips/BTips/Zavgorodni
// Tips Website    : Delphi Collection Tips
// Tips Website URL: http://www.delphicollection.com/public/Tips/
// ******************************************************************

// After inserting this code in program it will start only once at the windows session.

procedure TForm1.FormShow(Sender : TObject);
var
atom : integer;
CRLF : string;
begin
if GlobalFindAtom(‘THIS_IS_SOME_OBSCUREE_TEXT’) = 0 then
atom := GlobalAddAtom(‘THIS_IS_SOME_OBSCUREE_TEXT’)
else
begin
CRLF := #10 + #13;
ShowMessage(‘This programm will start only once’ + CRLF +
‘for next start reboot windows please, or…’ + CRLF +
‘REGISTER PROGRAM !!’);
Close;
end;
end;

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet

ALLOW ONLY ONE INSTANCE OF A PROGRAM (WORKS ALSO UNDER NT)

// ******************************************************************
// ALLOW ONLY ONE INSTANCE OF A PROGRAM (WORKS ALSO UNDER NT)
// Category        : Application – Others
// Author          : DelphiFAQ.com
// Author Email    : tips@delphifaq.com
// Author Web      : http://www.delphifaq.com
// Tips Website    : Delphi FAQ
// Tips Website URL: http://www.delphifaq.com
// ******************************************************************

// Just add this unit to your uses clause

uses Single;

// and your program will not be started twice:

unit Single;

interface

implementation uses Windows, SysUtils;

var hnd: THandle;

initialization
hnd := CreateMutex(nil, True, ‘irgendwaseinmaliges’);
if GetLastError = ERROR_ALREADY_EXISTS then Halt;

finalization
if hnd <> 0 then CloseHandle(hnd);
end.

October 21, 2007 Posted by Musriah | Application - Others | | No Comments Yet