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 | Application - Task | | Leave a comment

SETTING UP THE MDI PARENT WINDOW CORRECTLY

// ******************************************************************
// SETTING UP THE MDI PARENT WINDOW CORRECTLY
// Category        : MDI
// Author          : Michael Burton
// Author Email    :
// Author Web      : http://www.rimrocksoftware.com/tips.html
// Tips Website    : Rimrock Software
// Tips Website URL: http://www.rimrocksoftware.com/tips.html
// ******************************************************************

{
Delphi does not set up the MDI parent window correctly. Use the following to set
the proper border for the MDI parent window.
}

SetWindowLong(ClientHandle, GWL_EXSTYLE, WS_EX_CLIENTEDGE);
SetWindowPos(ClientHandle, HWND_BOTTOM, 0,0,0,0,SWP_NOCOPYBITS);

// (From Russ Reese)

November 6, 2007 Posted by | Application - MDI | | Leave a comment

CLOSE A MDICHILD FORM

// ******************************************************************
// CLOSE A MDICHILD FORM
// Category        : MDI
// Author          : Carlos Borrero
// Author Email    : cbarrer@elsitio.net.co
// Author Web      :
// Tips Website    : Swiss Delphi Center
// Tips Website URL: http://www.swissdelphicenter.ch
// ******************************************************************

unit Child;

// Have you noticed that when you try to close a MDIChild form
// the form minimizes but doesn’t disappear from your Main form
// client area?
//
// With this tip you can learn how to really close the MDI child
// form and free the memory occupied by the form

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TMDIChildForm = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MDIChildForm: TMDIChildForm;

implementation

{$R *.DFM}

procedure TMDIChildForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
// This line of code frees memory and closes the form
Action := caFree;
end;

end.

November 6, 2007 Posted by | Application - MDI | | Leave a comment

TOOLTIP FONT HINT PROPERTIES

// ******************************************************************
// TOOLTIP FONT HINT PROPERTIES
// Category        : Hint/ToolTip
// Author          : Zarko Gajic
// Author Email    : delphi.guide@about.com
// Author Web      : http://www.delphi.about.com
// Tips Website    : About Delphi Pages
// Tips Website URL: http://www.delphi.about.com
// ******************************************************************

{Change the font in Tool Tip (Hint box)}

Type
TMyHintWindow = Class (THintWindow)
Constructor Create (AOwner: TComponent);override;
end;

Constructor TMyHintWindow.Create(AOwner:TComponent);
begin
Inherited Create (AOwner);
Canvas.Font.Name := ‘Courier New’;
Canvas.Font.Size := 72;
end;

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

November 6, 2007 Posted by | Application - Hint / Tool Tips | | Leave a comment

MULTILINES HINT

// ******************************************************************
// MULTILINES HINT
// Category        : Hint/ToolTip
// Author          : Greatis Software
// Author Email    :
// Author Web      : http://www.greatissoftware.com
// Tips Website    : Greatis Software
// Tips Website URL: http://www.greatis.com/delphi/tips.html
// ******************************************************************

{
Creating multiline hint is not so difficult. Set ShowHint of Button1 to True and
try this:
}

procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Hint:=’Greatis’+#13+’Delphi Pages’;
end;

November 6, 2007 Posted by | Application - Hint / Tool Tips | | Leave a comment

MORE LINES IN A HINT

// ******************************************************************
// MORE LINES IN A HINT
// Category        : Hint/ToolTip
// Author          : Studiebureau Festraets
// Author Email    :
// Author Web      : http://www.festra.com/eng/index.html
// Tips Website    : Delphi Land
// Tips Website URL: http://www.festra.com/eng/index.html
// ******************************************************************

{
If you want to display more than a one line in the hint of a component, for
example of Button1, set it’s property ShowHint to true. In the Object Inspector,
don’t put anything in Button1’s hint property.

In the FormCreate event handler of the form that contains Button1, add this line:

Button1.Hint := ‘First line’ + Chr(13) + ‘Second line’;
}

November 6, 2007 Posted by | Application - Hint / Tool Tips | | Leave a comment

CREATE YOUR OWN HINTS

// ******************************************************************
// CREATE YOUR OWN HINTS
// Category : Hint/ToolTip
// Author : Domas Savickas
// Author Email : domass@takas.lt
// Author Web : http://ddelphi.hypermart.net/delphi
// Tips Website : Domas Delphi Pages
// Tips Website URL: http://ddelphi.hypermart.net/delphi
// ******************************************************************

{
If you don’t quite like the way how Delphi’s default hints look like,
you can use THintWindow component to create your own customized hint window.
Here’s an example:
}

var
h : THintWindow;
r : TRect;
begin
with r do
begin
//
// set the position and size
// of the hint window
//
left := 10;
top := 50;
right := 200;
bottom := 100;
end;
h := THintWindow.Create( Self );
with h do
begin
//
// set the background color
//
Color := clRed;

ActivateHint( r, ‘hi there!’ );

//
// perform your tasks here
// before closing the hint window
//
MessageBox( 0,
‘Press any key to close the ‘
+ ‘hint window’,
‘THintWindow’,
MB_OK );

ReleaseHandle;
Free;
end;
end;

November 6, 2007 Posted by | Application - Hint / Tool Tips | | Leave a comment

CREATE A NONSTANDARD REGION OF HINT

// ******************************************************************
// CREATE A NONSTANDARD REGION OF HINT
// Category        : Hint/ToolTip
// Author          : Greatis Software
// Author Email    :
// Author Web      : http://www.greatissoftware.com
// Tips Website    : Greatis Software
// Tips Website URL: http://www.greatis.com/delphi/tips.html
// ******************************************************************

{
First of all, you should create a new class with ActiveHint procedure. When you
create form, you should set HintWindowClass to your new class (TMyHint).
Try this:
}

TMyHint = class(THintWindow)
private
FRegion: THandle;
public
procedure ActivateHint(Rect: TRect; const AHint: string); override;
end;

// …

procedure TMyHint.ActivateHint(Rect: TRect; const AHint: string);
begin
SetWindowRgn(Handle, 0, True);
DeleteObject(FRegion);
BoundsRect:=Rect;
FRegion:=CreateEllipticRgn(0,0,Width,Height);
SetWindowRgn(Handle, FRegion, True);
inherited ActivateHint(Rect, AHint);
end;

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

November 6, 2007 Posted by | Application - Hint / Tool Tips | | Leave a comment

CONNECT TO AN FTP SERVER AND DOWNLOAD A FILE

// ******************************************************************
// CONNECT TO AN FTP SERVER AND DOWNLOAD A FILE
// Category        : FTP
// 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
// ******************************************************************

{
The following function shows how to connect to a ftp server
and download a file.
It uses the functions from wininet.dll.

You need a ProgressBar to show the progress and a Label to show progress informations.
}

uses
WinInet, ComCtrls;

function FtpDownloadFile(strHost, strUser, strPwd: string;
Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean;

function FmtFileSize(Size: Integer): string;
begin
if Size >= $F4240 then
Result := Format(‘%.2f’, [Size / $F4240]) + ‘ Mb’
else
if Size < 1000 then
Result := IntToStr(Size) + ‘ bytes’
else
Result := Format(‘%.2f’, [Size / 1000]) + ‘ Kb’;
end;

const
READ_BUFFERSIZE = 4096;  // or 256, 512, …
var
hNet, hFTP, hFile: HINTERNET;
buffer: array[0..READ_BUFFERSIZE – 1] of Char;
bufsize, dwBytesRead, fileSize: DWORD;
sRec: TWin32FindData;
strStatus: string;
LocalFile: file;
bSuccess: Boolean;
begin
Result := False;

{ Open an internet session }
hNet := InternetOpen(‘Program_Name’, // Agent
INTERNET_OPEN_TYPE_PRECONFIG, // AccessType
nil,  // ProxyName
nil, // ProxyBypass
0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE

{
Agent contains the name of the application or entity calling the Internet functions
}

{ See if connection handle is valid }
if hNet = nil then
begin
ShowMessage(‘Unable to get access to WinInet.Dll’);
Exit;
end;

{ Connect to the FTP Server }
hFTP := InternetConnect(hNet, // Handle from InternetOpen
PChar(strHost), // FTP server
port, // (INTERNET_DEFAULT_FTP_PORT),
PChar(StrUser), // username
PChar(strPwd),  // password
INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?
0, // flag: 0 or INTERNET_FLAG_PASSIVE
0);// User defined number for callback

if hFTP = nil then
begin
InternetCloseHandle(hNet);
ShowMessage(Format(‘Host “%s” is not available’,[strHost]));
Exit;
end;

{ Change directory }
bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir));

if not bSuccess then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
ShowMessage(Format(‘Cannot set directory to %s.’,[ftpDir]));
Exit;
end;

{ Read size of file }
if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil then
begin
fileSize := sRec.nFileSizeLow;
// fileLastWritetime := sRec.lastWriteTime
end else
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
ShowMessage(Format(‘Cannot find file ‘,[ftpFile]));
Exit;
end;

{ Open the file }
hFile := FtpOpenFile(hFTP, // Handle to the ftp session
PChar(ftpFile), // filename
GENERIC_READ, // dwAccess
FTP_TRANSFER_TYPE_BINARY, // dwFlags
0); // This is the context used for callbacks.

if hFile = nil then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Exit;
end;

{ Create a new local file }
AssignFile(LocalFile, TargetFile);
{$i-}
Rewrite(LocalFile, 1);
{$i+}

if IOResult <> 0 then
begin
InternetCloseHandle(hFile);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Exit;
end;

dwBytesRead := 0;
bufsize := READ_BUFFERSIZE;

while (bufsize > 0) do
begin
Application.ProcessMessages;

if not InternetReadFile(hFile,
@buffer, // address of a buffer that receives the data
READ_BUFFERSIZE, // number of bytes to read from the file
bufsize) then Break; // receives the actual number of bytes read

if (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) then
BlockWrite(LocalFile, buffer, bufsize);
dwBytesRead := dwBytesRead + bufsize;

{ Show Progress }
ProgressBar.Position := Round(dwBytesRead * 100 / fileSize);
Form1.Label1.Caption := Format(‘%s of %s / %d %%’,[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]);
end;

CloseFile(LocalFile);

InternetCloseHandle(hFile);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Result := True;
end;

October 28, 2007 Posted by | Ftp | | Leave a comment

ACCESSING HOTMAIL FROM DELPHI

// ******************************************************************
// ACCESSING HOTMAIL FROM DELPHI
// Category        : E-Mail, News
// 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:
Is it possible to access a hotmail account through the POP3 and SMTP? I know its
a web frontend but I’d like to write a automated application which can send and
recieve mail using a Hotmail account.

A:
Hotmail isn’t accessable through POP/SMTP. you must use their web interface.
There is no possible shortcut to read mail but you can open the default Hotmail
account in new message mode using this ShellExecute call:
}

program dummy;

var
ToAddress: String;
EightSpaces: String;

begin
ToAddress := ‘john@pacbell.net’;
// Don’t know why but this is required to get the
// correct compose address…
EightSpaces := ‘        ‘;
ShellExecute(Handle, PChar(‘open’), PChar(‘rundll32.exe’),
PChar(‘C:\PROGRA~1\INTERN~1\HMMAPI.DLL,MailToProtocolHandler’
+ EightSpaces + ToAddress), nil, SW_NORMAL)
end.

October 28, 2007 Posted by | Email | | Leave a comment