INDODELPHI

Blog’s Tutorial Delphi – Reference from Onez Delphi Explorer

USE PROGRAM PARAMETERS

// ******************************************************************
// USE PROGRAM PARAMETERS
// 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
// ******************************************************************

{
Paramstr(1) is the first parameter
Paramstr(0) is the full program path
}

procedure TForm1.FormShow(Sender: TObject);
var
parameter:string;
begin
parameter:=Paramstr(1);
if parameter=’/message’ then
begin
ShowMessage(‘Parameter /message’);
end;
if parameter=” then
begin
ShowMessage(‘No parameter’);
end;
end;

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

USE VISUAL STYLES FROM XP IN THE OWN APPLICATION

// ******************************************************************
// USE VISUAL STYLES FROM XP IN THE OWN APPLICATION
// Category : Application – Others
// Author : Thomas Stutz
// Author Email : tom@swissdelphicenter.ch
// Author Web : http://www.swissdelphicenter.ch
// Tips Website : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

{
To benefit from the new look and feel (Visual Styles) for the Windows XP
environment, you must include a Manifest in your application.
(Either as resource or as file in the same directory where your application
resides)

The manifest is a XML document. It will allow Windows XP to decide which
version of the comctl32.dll to use when binding.
The XML document contains information about the application you are
writing as well as information concerning the version of the comctl32.dll to use.

The following instruction shows how to
* create the manifest document
* create the XP resource file
* include the file in your application

The steps 1-4 show how to create the files.
You can also download the manifest and resource file from the
Demo-download.

1)
Copy this sample manifest and paste it into notepad or any text editor.
}

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<assembly xmlns=”urn:schemas-microsoft-com:asm.v1″ manifestVersion=”1.0″>
<assemblyIdentity
version=”1.0.0.0″
processorArchitecture=”X86″
name=”CompanyName.ProductName.MyProgram”
type=”win32″
/>
<description>Your Application Description</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type=”win32″
name=”Microsoft.Windows.Common-Controls”
version=”6.0.0.0″
processorArchitecture=”X86″
publicKeyToken=”6595b64144ccf1df”
language=”*”
/>
</dependentAssembly>
</dependency>
</assembly>

{
2)
To customize to fit your application, replace “name” from assemblyIdentity and the
“description” string with your own data. Then save the file as WinXP.manifest

3)
Create another file which contains instructions to include the
WinXP.manifest (XML) document.
The contents of the WinXP.rc looks like this:
}

1 24 “WinXP.manifest”

{
4)

Now we need to use Delphi’s resource compiler (brcc32.exe) to compile the WinXP.rc file.
Doing so will result in a WinXP.res
From the command line, type the following:
}

brcc32 WinXP.rc

(*
5)
Now include the resource in your application.
Include the following compiler directive:
immediately after {$R *.DFM}:
*)

{$R WinXP.res}

{
6)
Compile your application and run it!

7)
Test it if it runs correctly.
Note that some controls don’t adapt the new XP design such
as TGroupBox, TSpeedButton and some others.
If you use the TListView component with the view style of vsReport, have a look at this tip:
http://www.swissdelphicenter.ch/de/showcode.php?id=1117
}

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

DETECT AND DOWNLOAD A NEW VERSION OF (AN OWN) APPLICATION

// ******************************************************************
// DETECT AND DOWNLOAD A NEW VERSION OF (AN OWN) APPLICATION
// Category        : Application – Others
// Author          : MT
// Author Email    : tsoft@home.ro
// Author Web      : http://tsoft.home.ro
// Tips Website    : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

uses
{…,}IniFiles, UrlMon,

type
TForm1 = class(TForm)
{…}
private
winsc: TiniFile;
old: Integer;
vernfo: TIniFile;
end;

implementation

{$R *.dfm}

function DownloadFile(Source, Dest: string): Boolean;
{ Function for Downloading the file found on the net }
begin
try
Result := UrlDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;

function GetPathPath: string;
{ Retrive app path }
begin
Result := ExtractFilePath(Application.ExeName);
end;

procedure TForm1.DownLoadNewVersion1Click(Sender: TObject);
var
apath: string;
new: Integer;
begin
// This is the exact code from my application
apath           := GetPathPath;
Gauge1.Progress := 0;
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText := ‘Connecting to http://tsoft.home.ro’;
Gauge1.Progress := 20;
if DownloadFile(‘http://www.tsoft.home.ro/update.ini’, PChar(apath) + ‘/update.ini’) then
begin
Gauge1.Progress := 50;
StatusBAr1.SimplePanel := True;
StatusBar1.SimpleText := ‘Checking for newer versions…’;
vernfo := TiniFile.Create(GetPathPath + ‘/update.ini’);
new    := vernfo.ReadInteger(‘version’, ‘wsc’, 7);
vernfo.Free;
if (old = new) then
begin
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText  := ‘No new version detected’;
Gauge1.Progress        := 100;
end
else if DownloadFile(‘http://www.tsoft.home.ro/winsafe.exe’,
PChar(apath) + ‘/winsafe.exe’) then
begin
ShowMessage(‘Update succeseful’);
Gauge1.Progress := 100;
winsc           := TIniFile.Create(ChangeFileExt(Application.ExeName, ‘.ini’));
winsc.WriteInteger(‘wsc’, ‘vernfo’, new);
winsc.Free;
end
else
MessageDlg(‘A new version has appeard but it requires a second install’,
mtInformation, [mbOK], 0);
end
else
begin
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText  := ‘Failed to connect probably a internet problem’;
Gauge1.Progress        := 0;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//App version
winsc := TIniFile.Create(ChangeFileExt(Application.ExeName, ‘.ini’));
try
old := winsc.ReadInteger(‘wsc’, ‘vernfo’, 1);
finally
winsc.Free;
end;
end;

end.

{
The concept is very simple u download a ini file from your website that contains
the version you compare it with the one from your computer and it downloads the
file if the versions are Not equal if you find any froblems write me.
}

October 21, 2007 Posted by maulaku | Application - Others | | 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