THE VANNI'S TIPS & TRICKS PAGE


Click here to e-mail me

 

secchione.gif (6005 byte) In this page you can find several tips & tricks made by myself.
Tips are divided by Begginer Tips or Advanced Tips

This page was created by Brutto Vanni








This are tips dedicated to people who haven't experince with Delphi 2.0.

Several of these questions were made from people who coded with Visual Basic.


1. How can i convert a String to an Integer and viceversa?
You can easly convert a String to an Integer with STRtoINT function, INTtoSTR work at the opposite.

2. Can Delphi convert a Currency type to a String?
Apparently Delphi can't do it, you can however download this unit that able to access you CURtoSTR and STRtoCUR functions. To use this unit you must add it to your project, after that you can add CurUnit in uses part of your unit. Note that conversion is made in case of your Windows language, so for example italian users must use "," as decimal separator and "." as thousand separator, so 1.000.000,23 return 1000000.23. If it doesn't work e-mail me what error kind happen.

3. I'm looking for a way to hide the Caption (or Title) bar of my application. I want to have a Sizable Window with no Caption Bar. Is this possible?
You might try this method connected to onCreate event:

SetWindowLong(Handle,GWL_STYLE, GetWindowLong(Handle,GWL_STYLE) AND NOT WS_CAPTION);
ClientHeight := Height;

3. How can i make a TEdit component that lost focus when user press ENTER?
Here is a custom TEdit that will tab to the next control when the user hits the <ENTER>






This are tips dedicated to people that know how to use Delphi.



1. Can a Delphi application show standard Win '95 effect when i minimize my application windows?
Yes, but it is not very simple, i suggest to you download this sample who show you how to make this effect

2. I'm looking for a Debug Box like Visual Basic, does Delphi 2.0 have it?
No, it hasn't. However you can install the TDebugBox component made by myself that is very similar to Visual Basic debug box. I suggest you to download TDebugBox component who show you

3. Someone told me of a cheat in Delphi 2.0, it's true?
Yes, type these words in About Box window:

|alt| A-N-D Picture of Anders Hejlsberg
|alt| T-E-A-M A list of those responsible for this fine product
|alt| D-E-V-E-L-O-P-E-R-S A list of the R&D folks specifically



4. If you have the date 1/1/2000 and run the following code: DateToStr(StrToDate('1/1/2000')) the year gets changed from 2000 to 1900. What's the best way to handle this?
The value of the typed constant ShortDateTime in WIN.INI determines how DateToStr and StrToDate convert strings. The default is dd/mm/yy - two digit year. You can solve the probleme using
ShortDateFormat:= 'dd/mm/yyyy';
instruction in formcreate event of your main form application.


5. How can i intercept a window message?
I Think that tips 6 will reponse your question!

6. How can i drag a window with a click in its foreground area?
It's not so difficult: make a new project with main form named Form1 and its unit Unit1, change its code with this:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
protected
procedure WMLButtonDown(var Message: TWmLButtonDown); message WM_LBUTTONDOWN;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMLButtonDown(var Message: TWmLButtonDown);
begin
  if Message.Keys = MK_LBUTTON Then begin
    DefWindowProc(handle, WM_NCLBUTTONDOWN, 2, 0) //If Left click pressed...
  End Else Begin
    inherited; //Else standard function
  End;
end;

end.

 

 

7. Can i move a file in Recycle Bin (Cestino in Italiano) when i delete a file?
Yes, simple download this unit that enable you to do it!

8. Can i see assembly code of my program?
Yes, follow this method for able a new function on Delphi

Punto.gif (924 byte) Exit Delphi
Punto.gif (924 byte) Run "Registry Editor" (run regedit.exe or regedt32.exe)
Punto.gif (924 byte) Select following registry key:

Version 2.0: HKEY_CURRENT_USER\Software\Borland\Delphi\2.0\Debugging
Version 3.0: HKEY_CURRENT_USER\Software\Borland\Delphi\3.0\Debugging

Punto.gif (924 byte) Add an string item named "EnableCPU" and set its value to "1" (without the quotes)
Punto.gif (924 byte) Exit Registry Editor
Punto.gif (924 byte) Restart Delphi and select "View | CPU"

Now when you debug your program, you'll see the assembly instructions in the new "DisassemblyView" window.

9. There's a way to make a system hook proc in Delphi?
This is an interesting problem that take me a lot of time to solve... download this sample that will show you how to globally trap keyboard pressions. Note that it seems crash DirectX application, i hope solve also this bug in future.

10. I'm looking for a way to run my app at startup
It's easy enough to drag and drop your application to the Startup group to make it run on Windows startup. But, if you wanted to do this programmatically (at the end of your setup program for example), or if you wanted to make your program run only the next time Windows start, following function might come in handy:

procedure RunOnStartup(sProgTitle, sCmdLine: string; bRunOnce: boolean);
var
  sKey : string;
  reg  : TRegIniFile;
begin
  if( bRunOnce )then begin
    sKey:= 'Once';
  end else begin
    sKey := '';
  end;

  reg:= TRegIniFile.Create('');
  reg.RootKey:= HKEY_LOCAL_MACHINE;
  reg.WriteString('Software\Microsoft' + '\Windows\CurrentVersion\Run' + sKey + #0, sProgTitle, sCmdLine );
  reg.Free;
end;



Usage:
sProgTitle: Name of your program. Generally speaking, this could be anything you want.
sCmdLine: This is the full path name to your executable program.
bRunOnce: Set this to True if you want to run your program just once. If this parameter
is False, your program will be executed every time Windows startsup.
Example:
RunOnStartup( 'Title of my program', 'MyProg.exe', False );