Tutorial Delphi

Installing new components

Here we will give examples of how to install a new component in Delphi 3. Previously downloaded first IEButton components. The way is as follows:

A. Once you download and extract the file, then you will get four files. Copy these four files into lib directory (usually C: \ Program Files \ Borland \ Delphi 3 \ Lib).
2. Run your Delphi program. From the Component menu, select Install Component.
3. On the Unit File Name, click Browse and navigate to the location IEBtn.pas file (C: \ Program Files \ Borland \ Delphi 3 \ Lib \ IEBtn.pas).
4. Package to the File Name, you can fill up with C: \ Program Files \ Borland \ Delphi 3 \ Lib \ dclusr30.dpk.
5. Click OK.
6. If installation is successful it will be visible component parts on the Win95 IEButton.
 
Knowing the path of the application
 
In making the application, sometimes we need to know the path or location of the file *. Exe of a program. How do I?

The way is easy. You just simply add a property ExeName of TApplication class.

procedure TForm1.Button1Click (Sender: TObject);
begin
Label1.Caption: = Application.ExeName;
end;

Pieces on the program will "look for" the location of the file *. Exe and write it on the Label1 component, if the user clicks Button1.
 
Changing RegisteredOwner & Organization
 
Before you go ahead with this Delphi tutorial, you have to understand the ins and outs of the registry first. Please read the registry review briefly here.
This tutorial will explain how to replace RegisteredOwner and RegisteredOrganization on your computer. RegisteredOwner and Organization can be seen in the Control Panel - System, then on the Registerd To. RegisteredOwner to replace the "manual" (via the registry editor) you can see here.
The first step before manipulating the value in the registry is to inform key advance that will be accessed. You do this by changing the properties RootKey. Contents of this property is HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, or HKEY_USERS. By default the value of this property is HKEY_CURRENT_USER, so if you do not fill the property, Delphi will assume as HKEY_CURRENT_USER.Example:
varMyReg: TRegistry;beginMyReg: = TRegistry.Create;MyReg.RootKey: = HKEY_LOCAL_MACHINE;.MyReg.Free;end;
The second step is to open the subkey to be manipulated, that is by calling the function OpenKey. OpenKey function declaration is as follows:
OpenKey function (const Key: string; CanCreate: Boolean): Boolean;
There are two parameters that must be filled. The first parameter of type string which is a subkey to be opened. While the second parameter of type boolean, which will determine whether the subkey to be created or not. When this parameter is true, then Delphi will create the registry subkey if it does not exist. Conversely, if false, subkey will not be made even if the registry does not exist. OpenKey function will return true if initialization was successful and returns false if it fails.
To change RegisteredOwner, the subkey is: \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \
Thus, we have to write code that is:
MyReg.RootKey: = HKEY_LOCAL_MACHINE;MyReg.OpenKey: = ('\ SOFTWARE \ Microsoft \ Windows \ CurrentVersion', false);
After the above steps, then you can read or write data to the registry. To read the data in the registry you can use ReadString, ReadInteger, etc. (read his pd Delphi Help file). As for the write data to the registry using WriteString, WriteInteger, etc..
The code below shows how the reading of data in the registry, the results are written on Edit1 components.
Edit1.Text: = MyReg.ReadString ('RegisteredOwner');Edit2.Text: = MyReg.ReadString ('RegisteredOrganization');
As for the writing of data to the registry using the following ways:
reg.WriteString ('RegisteredOwner', Edit1.Text);reg.WriteString ('RegisteredOrganization', Edit2.Text);
 
Shutdown the computer
 
To restart, shutdown or log off the computer, use the function ExitWindowsEx. There were declarations of ExitWindowsEx function is as follows:

ExitWindowsEx function (uFlags: word; dwReserved: DWORD): BOOL;

The first parameter to explain "what should be done" by the computer. This parameter can be valuable:
constants

information
Restart EWX_RESTART by displaying a warning.
Doing EWX_SHUTDOWN shutdown by displaying a warning.
Doing EWX_LOGOFF log off by displaying a warning.
Doing EWX_FORCE shutdown without displaying a warning. So there is a chance you will lose any unsaved data (not on-save).

While the second parameter is 0.

So if you want to perform shutdown simply write the following code:

ExitWindowsEx (EWX_SHUTDOWN, 0);
 
Running other Windows applications
 
To run other Windows applications from your program, you can use one of the Windows API function, which is WinExec. The declaration of WinExec function is as follows:

WinExec function (lpCmdLine: PChar; uCmdShow: integer): integer;

The first parameter is the name of the file *. Exe which will run along the paths.

The second parameter indicates how the application is run. This parameter can be valuable:
parameter

meaning
Showing SW_SHOWMINIMIZED minimal application (shaped icon)
Showing SW_SHOWMAXIMIZED application with (size) of the maximum window
Showing SW_SHOWNORMAL normal application window
* There are nine other parameter values ​​that you can see the references in the Windows API ShowWindow

WinExec function will return a value greater than 31 if the application works. Whereas if it fails, the return value is less than or equal to 31. Details of the return value is:
Returns the value of

meaning
0 Windows run out of memory or resources
File ERROR_BAD_FORMAT not run a Windows application file
ERROR_FILE_NOT_FOUND run File not found
ERROR_PATH_NOT_FOUND wrong file path

The following example may clarify your will.

procedure TForm1.Button1Click (Sender: TObject);
begin
if (WinExec ('C: \ Windows \ notepad.exe',
SW_SWOWMAXIMIZED) <32) then
MessageDlg ('Failed to run Notepad',
mtError, [Mbok], 0);
end;

In the example above, when the user clicks Button1 then the program will run Notepad.exe file located in C: \ Windows.
 
hiding the taskbar
 
The example program below will show you how to hide the taskbar through a program created with Delphi.

To hide and show taskbar you can use one of the Windows API function ShowWindow a declaration is as follows:

function ShowWindow (hwnd: HWND; nCmdShow: integer): Boolean;

The first parameter is the handle of the window ShowWindow function to be displayed or hidden. The second parameter is how the window is displayed. The question we are, where we get the window handle of the taskbar? The trick is to call the FindWindow function.

function FindWindow (lpClassName, lpWindowName: PChar): HWND;

The first parameter is the window class name (window class). At Delphi's name is synonymous with the name of the Form class, for example TForm1, TForm2, and so on. The second parameter is the caption of the form (TForm.Caption).

FindWindow function returns the handle of a searchable form. If Windows does not find the form in question, FindWindow will return the value 0.

To find a form handle of the taskbar:

FindWindow ('Shell_TrayWnd', Nil);

The first parameter of FindWindow is filled with Shell_TrayWnd the window class of the taskbar. While the second parameter is filled with Nile taskbar indicating that the form has no caption.

More code to hide the taskbar is as follows:

procedure TForm1.Button1Click (Sender: TObject);
var
hTaskBar: Thandle;
begin
hTaskBar: = FindWindow ('Shell_TrayWnd', Nil); ShowWindow (hTaskBar, SW_HIDE);
end;

To show the taskbar with the same steps above. The only difference is the second parameter of the ShowWindow, SW_HIDE initially replaced with SW_NORMAL. The full code is as follows:

TForm2.Button1Click procedure (Sender: TObject);
var
hTaskBar: Thandle;
begin
hTaskBar: = FindWindow ('Shell_TrayWnd', Nil); ShowWindow (hTaskBar, Sw_Normal);
end;

Download SampleClick Here
 
Running the applet on the control panel
 
To run the applet on the control panel range, you can use one of the Windows API function that is WinExec.

WinExec function (lpCmdLine: PChar; uCmdShow: integer): integer;

See the information WinExec function here.

Suppose you want to open the Add / Remove Programs then you have to write code like this:

procedure TForm1.Button1Click (Sender: TObject);
begin
WinExec ('C: \ WINDOWS \ control.exe appwiz.cpl, Add / Remove Programs, 1', SW_NORMAL);
end;

You also can create your own function to run the applet on the control panel.

RunApplet function (const AppletName: string): integer;
begin
Result: = WinExec (PChar ('rundll32.exe shell32.dll,' + 'Control_RunDLL' + AppletName), SW_SHOWNORMAL);
end;

Example of use: RunApplet ('appwiz.cpl');

You can replace the above with appwiz.cpl applet you want to open. Applet file name and description:

access.cpl = Accessibility Options
appwiz.cpl = Add / Remove Programs
desk.cpl = Display Properties
intl.cpl = Regional Settings
joy.cpl = Joystick
main.cpl = Mouse
mmsys.cpl = Multimedia
modem.cpl = Modems Properties
netcpl.cpl = Network Properties
password.cpl = Password Settings
sysdm.cpl = System Properties
timedate.cpl = Time / Date Settings

Download Example : Click Here
 
Check disk on the disk drive
 
If you do not want to see the message "A: \ is not accessible. The Device not Ready" when you access the disk drive is empty (there is no diskette in the disk drive), use the following code:

procedure TForm1.Button1Click (Sender: TObject);
begin
if not DirectoryExists ('a: \') then
MessageDlg ('Disk drive empty', mtError, [Mbok], 0) else
{if the disk drive is not empty then.}
end;

So when the user accesses the disk drive is empty, a message which is more easily understood, the "Disk drive is empty".
 
Hide icon on the desktop
 
The example program below will show you how to hide the icon on the desktop through a program created with Delphi.

Description of Show Window and FindWindow function can be viewed here.

procedure TForm1.Button1Click (Sender: TObject);
begin
ShowWindow (FindWindow (nil, 'Program Manager'), SW_HIDE);
end;

procedure TForm1.Button2Click (Sender: TObject);
begin
ShowWindow (FindWindow (nil, 'Program Manager'), SW_SHOW);
end;

Download SampleClick Here
 
Creating a splash screen
 
                 The splash screen is a display that we saw our first time running an application. The splash screen is typically displayed to reduce the saturation of the user while the program is still in the initialization phase.

To make a splash scren the following way:

A. First make the main form.
2. Add form to be used as a splash screen (from the File menu, choose New Form). Give the name of the form by FrmSplash.
3. Add Timer component (located on the Win32 tab), name the tmMainTimer.
4. Add the following code to the events onTimer of the Timer component:

tmMainTimer.Enabled: = False;

5. From the Project menu, choose Options.
6. Move to the Forms tab.
7. Create forms of auto parts will be seen two forms. Select Form to be used as a splash screen and click the ">" to move the splash screen form to the Available forms.
8. If it is click OK.
9. Now from the View menu, select Project Source. In the main program make a splash screen form before initialization done.

For more details, see the following program snippet:

program Project1;

uses Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' FrmSplash {};

{$ R *. RES}

begin
FrmSplash: = TFrmSplash.Create (Application);
FrmSplash.Show;
FrmSplash.Update;
while FrmSplash.tmMainTimer.Enabled do Application.ProcessMessages;
Application.Initialize;
Application.CreateForm (TForm1, Form1);
FrmSplash.Hide;
FrmSplash.Free; / / remove the splash scren form dr memory
Application.Run;
end.

Download SampleClick Here
 
Tips & tricks about the hint
 
Hint is the text that appears when the mouse pointer over an object (bi sa form of buttons, forms, list boxes, etc.). The default hint is performed for 2.5 seconds. But by adding a little Delphi code below, you can change the time, could be faster or longer.

Replacing the old days of hint

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

Creating a hint of two lines:

Button1.Hint: = 'Line 1' # 13 # 10'Baris 2 ';
 
Creating a desktop icon text transparent reply
 
The splash screen is a display that we saw our first time running an application. The splash screen is usually displayed to

Commctrl uses;

var
hLV: THandle;

TForm1.GetDesktopListViewHandle procedure;
var
s1: string;
begin
hLV: = FindWindow ('ProgMan', nil);
hLV: = GetWindow (hLV, GW_CHILD);
hLV: = GetWindow (hLV, GW_CHILD);
SetLength (s1, 40);
GetClassName (hLV, PChar (s1), 39);
if PChar (s1) <> 'SysListView32' then
ShowMessage ('Failed');
end;

procedure TForm1.Button1Click (Sender: TObject);
var
xColor: TColor;
begin
GetDesktopListViewHandle;
xColor: = ListView_GetTextColor (hLV);
ListView_SetTextColor (hLV, xColor);
xColor: = ListView_GetTextBkColor (hLV);
ListView_SetTextBkColor (hLV, xColor);
ListView_SetTextBkColor (hLV, $ FFFFFFFF);
end;

Download SampleClick Here
 
refresh the desktop
 
Below is the code that can be used to refresh the desktop without having to press F5.

procedure TForm1.Button2Click (Sender: TObject); begin
SendMessage (FindWindow ('Progman', 'Program Manager'), WM_COMMAND, $ A065, 0);
winexec (PChar ('rundll32 user, repaintscreen'), sw_Show);
end;

Download SampleClick Here
 
Hide the caption bar
 
To hide the caption bar, add the code in onCreate event.


TForm1.FormCreate procedure (Sender: TObject);
begin

SetWindowLong (Handle, gwl_style, GetWindowLong (handle, gwl_style) and NOT ws_caption);
ClientHeight: = Height;
refresh;

end;
 
Move a form which has no caption bar
 
To move a form that does not have a caption bar, add the following code to the onmousedown event.

TForm1.FormMouseDown procedure (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

ReleaseCapture;
SendMessage (Form1.Handle, wm_SysCommand, $ f012, 0);

end;
 
Open the Control Panel
 
Use the code below to open the Control Panel from your Delphi program. Do not forget tampahkan ShellAPI on the uses:

TForm1.Buton1Click procedure (Sender: TObject);
begin
ShellExecute (Handle, 'Open', 'control',
nil, nil, SW_SHOWNORMAL);
end;
 
Gives color to the active record in TDBGrid 
 
Maybe you want to give color to the active record in the TDBGrid with another color (not the same color that does not record ing). To that add the following code in the event DBGrid.OnDrawColumnCell:

type
TCustomDBGridCracker = class (TCustomDBGrid);

TForm1.DBGrid1DrawColumnCell procedure (Sender: TObject;
const rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with TCustomDBGridCracker (Sender) do
if DataLink.ActiveRecord = Row - 1 then
Canvas.Brush.Color: = clRed
else
Canvas.Brush.Color: = clWhite;
DBGrid1.DefaultDrawColumnCell (rect, DataCol, Column, State);
end;

Download Sample: Click Here
 
Colors in DBGrid for which data
 
question:

How to color in DBGrid in accordance with the data that we have set, for example the color blue on Population Data record with more than 2.5 million?

answer:

Quite easy, you just add the following code in the event of the DBGrid OnDrawColumncell.:

TForm1.DBGrid1DrawColumnCell procedure (Sender: TObject; const rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName ('Population'). AsInteger> 25 million then
TDBGrid (Sender). Canvas.Brush.Color: = $ 00E9D358;
TDBGrid (Sender). DefaultDrawColumnCell (rect, DataCol, Column, State);
end;

If you want to replace with a field (column), you just replace the words "Population" at the top of the field names you want along with its data type.

example:

Table1.FieldByName ('Continent'). AsString = 'South America'

Download Sample: Click Here
 
Access to external equipment via Parallel Printer Port
by: Fuad Haharap
 
Want to control external equipment using a computer? Certainly a lot of fun, especially with just a few lines of Delphi program, we can turn on the lights, turn on the motor, set the robot arm or other electronic equipment to access.

Maybe this article can be a fairly nutritious snack for the likes Delphiers ngoprek practical electronics, this is because we do not have to make a card I / 0 itself, but simply to take advantage of any parallel printer port.

Parallel Printer Port
Port this one, certainly there are always at each computer. The name suggests, is currently more widely used parallel port for printing business data. Actually, even this port can be used for anything else, because it has an input / output (I / O) data.

The layout of the twenty-five-pin (DB 25) parallel printer port, shown in Figure 1.

[Image: delphi_port_1.gif]

Figure 1. Layout pin parallel printer port.

The signal table and the function of each pin on the parallel printer port, shown in Figure 2. From there it is known pin 2 s / d 9 (signals D0-D7) serves as an output, which can further be utilized to control external equipment.

[Image: delphi_port_2.gif]

Figure 2. Signal and function of the parallel printer port.

the circuit

For the purposes of a trial for a moment, we can connect the LED (Light Emitting Diode) through the resistor, directly to the output pin of the parallel printer port. It could also simply by measuring the resulting voltage of 5 volts, while the data port in a high state.

[Image: delphi_port_3.gif]

Figure 3. Scheme for temporary testing.

To gain access to a huge burden and to prevent excessive loading on the parallel printer port, you should use a series of buffer (buffer).
 
Access to external equipment via Parallel Printer Port
by: Fuad Haharap
 
Selanjutnya
sakelar pada setiap relai tersebut, bisa kita gunakan untuk
mengontrol peralatan yang memiliki beban besar.

Kode Program Delphi
Tidak seperti Turbo Pascal atau Delphi 1 dimana tersedia fungsi Port,
pada Delphi 32 bit (versi 2 s/d 6) fungsi itu sudah tidak didukung lagi.
Sebagai gantinya kita gunakan in-line assembler code.

Listing 1. Hidupkan LED 5 dari rangkaian pada Gambar 3.

procedure KirimDataKePort(AlamatPort: Word; DataBit: Byte);
(* alamat LPT1, range 378-37F hex
alamat LPT2, range 278-37F hex
alamat LPT3, range 3BC-3BF hex
lihat juga referensi teknis dari Intel dan Microsoft *)
asm
MOV DX, AlamatPort
MOV AL, DataBit
OUT DX, AL
end;

procedure TForm1.btnLED5Click(Sender: TObject);
begin
(* contoh pemanggilan prosedur KirimDataKePort,
ini akan menyalakan LED 5 (data bit-4 / pin 6
dari rangkaian yang terdapat pada Gambar 3. *)
KirimDataKePort($378, $8); //00010000 biner
end;

[Image: delphi_port_5.gif]

Gambar 5. Tampilan program kendali, dikembangkan dengan Delphi.

Pada prinsipnya, untuk menyalakan LED, kita kirim data biner
8 bit ke port. Sesuaikan pengiriman data biner ini, dengan LED
yang ingin dinyalakan.

Misalnya, untuk menyalakan LED pertama datanya adalah 1 hex
(biner; 0000001), sedangkan data biner 10000000
(80 hex / 128 dec) digunakan untuk menyalakan LED kedelapan.
Daftar berikut, dapat digunakan sebagai acuan.
DataPort Bit 0 = LED1 = 00000001 bin = 1 hex = 1 dec
DataPort Bit 1 = LED2 = 00000010 bin = 2 hex = 2 dec
DataPort Bit 2 = LED3 = 00000100 bin = 4 hex = 4 dec
DataPort Bit 3 = LED4 = 00001000 bin = 8 hex = 8 dec
DataPort Bit 4 = LED5 = 00010000 bin = 10 hex = 16 dec
DataPort Bit 5 = LED6 = 00100000 bin = 20 hex = 32 dec
DataPort Bit 6 = LED7 = 01000000 bin = 40 hex = 64 dec
DataPort Bit 7 = LED8 = 10000000 bin = 80 hex = 128 dec

Bagi yang ingin bereksperimen, Listing 2 merupakan kode program
dari contoh Aplikasi Pengendali seperti yang terlihat pada Gambar 5.

Listing 2. Kode program aplikasi pengendali.
(* = Mengontrol peralatan luar lewat Parallel Printer Port = *)
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Buttons, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
Bevel1: TBevel;
Bevel2: TBevel;
lblDataPortBit: TLabel;
lblNoLED: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure KirimDataKePort(DataPortBit: Byte);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

uses
Math;

const
AlamatPort = $378;

procedure TForm1.KirimDataKePort(DataPortBit: Byte);
var
Nilai: Byte;
begin
lblDataPortBit.Caption := IntToStr(DataPortBit);
lblNoLED.Caption := 'LED No. ' + IntToStr(DataPortBit + 1) +
' Nyala';
Nilai := Trunc(Power(2, DataPortBit));
asm
MOV DX, AlamatPort
MOV AL, Nilai
OUT DX, AL
end;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
(* Letakan 8 buah TSpeedButton, atur propeti Tag
dari 8 TSpeedButton tersebut dengan nilai
0 sampai dengan 7. Dari Object Inspector,
arahkan event Clik dari semua TSpeedButton
ke SpeedButon1Click. *)

KirimDataKePort((Sender as TSpeedButton).Tag);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
KirimDataKePort(0);
end;

end.
 
Knowing how long Windows starts
 
Uptime function: string;
const
ticksperday: integer = 1000 * 60 * 60 * 24;
ticksperhour: integer = 1000 * 60 * 60;
ticksperminute: integer = 1000 * 60;
tickspersecond: integer = 1000;
var
t: longword;
d, h, m, s: integer;

begin
t: = GetTickCount;

d: = t div ticksperday;
dec (t, d * ticksperday);

h: = t div ticksperhour;
dec (t, h * ticksperhour);

m: = t div ticksperminute;
dec (t, m * ticksperminute);

s: = t div tickspersecond;

Result: = 'Uptime:' + IntToStr (d) + 'Days' + IntToStr (h) + 'Hours' + IntToStr (m) + 'Minutes' + IntToStr (s) + 'Seconds';
end;

While the examples of its use are as follows:

procedure TForm1.Button1Click (Sender: TObject);
begin
Label1.Caption: = uptime;
end;
 
Delphi in the palette AutoScroll
 
Anda yang sudah familiar dengan Delphi tentunya tidak asing lagi dengan komponen-komponennya yang diletakkan pada palette. Pada Delphi 5 terdapat sekitar 19 palette. Dengan jumlah palette sebanyak itu tentunya Anda akan sering direpotkan dengan menggunakan scroll yang terletak pada kanan atas untuk berpindah dari satu palette ke palette yang lain.
Tapi untunglah Borland menyediakan satu feature yang tidak terdokumentasi yang dapat mempermudah kita untuk berpindah antar palette tersebut. Caranya adalah dengan sedikit otak-atik pada registry. Adapun langkah lengkapnya adalah sebagai berikut:

1. Dari menu Start, pilih Run.
2. Ketikkan regedit, klik OK.
3. Pindah ke key:
HKEY_CURRENT_USER\Software\Borland\5.0\
4. Dari sini bikin subkey baru. Caranya klik kanan pada key 5.0. Dari menu yang muncul pilih New - Key. Beri nama sub key baru tersebut dengan Extras.
5. Pindah ke subkey yang baru saja dibuat (subkey Extras).
6. Buat sebuah String Value. Caranya klik kanan, pilih New - String Value. Beri nama dengan AutoPaletteScroll. Beri nilai pada AutoPaletteScroll dengan 1.
7. Buat sebuah String Value lagi dengan nama AutoPaletteSelect dan beri nilai dengan 1.

Jika Anda telah mengubah registry dengan benar maka untuk berpindah antar palette Anda cukup meletakkan cursor mouse di atas judul palette (tanpa harus mengklik judulnya).

Untuk Anda yang belum familiar dengan registry, kami menyediakan file *.reg yang dapat langsung dimasukkan ke registry, tentunya setelah Anda.
 
Feature secrets on Delphi 5
 
This paper is a continuation of an earlier article entitled autoscroll in Delphi palette. Here we add two other hidden feature that is owned by Delphi 5.

A. Displays the font shape
By default, if we choose a property on the Object Inspector Font.Name then shown is the name of the font. By slightly altering the registry we can display the font name font along with his form.
The trick, add a new String Value named FontNamePropertyDisplayFontNames on
HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Extras. Fill in the data value to 1 FontNamePropertyDisplayFontNames.

2. Different color on the Object Inspector
As we have seen, both on the Properties and Events in the Object Inspector consists of two columns. Left column is for the Property or the Events column while the right is the "value" of his. Well, the brain-tweaking the registry again, we can make the color of the right hand column as they pleased us. The trick, add a new String Value named PropValueColor at HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Globals. Then fill it with a data value, for example clNavy, clRed, etc..

If you do not want hard-earned brain-tweaking the registry, please copy the line below and save the file name extension. Reg. To enter into the registry just click 2x on the file.
Good luck.

REGEDIT4

[HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Extras]
"AutoPaletteSelect" = "1"

[HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Extras]
"AutoPaletteScroll" = "1"

[HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Extras]
"FontNamePropertyDisplayFontNames" = "1"

[HKEY_CURRENT_USER \ Software \ Borland \ Delphi \ 5.0 \ Globals]
"PropValueColor" = "clRed"
 
Creating a gradient form
 
To beautify the look of the program that you created, you can create a gradient form. The trick is to add code to the OnPaint event of the form like the example below:

TForm1.FormPaint procedure (Sender: TObject);
var
Row, Ht: Word;
IX: Integer;
begin
ix: = 200;
Ht: = (+ ClientHeight 512) div 256;
for Row: = 0 to 512 do
begin
with Canvas do begin
Brush.Color: = RGB (Ix, 150, row);
FillRect (rect (0, Row * Ht, ClientWidth, (Row + 1) * Ht));
IX: = (IX-1);
end;
end;
end;

To change to another color, you can simply replace the line:

Brush.Color: = RGB (Ix, 150, row);

RGB is the color combination of Red, Green, Blue. The value that you can enter the RGB is 0 to 255.
 
Create a group on the report
 
By using components TQRGroup You can group the data under certain conditions. Suppose you want to group the names of tables Company Customter.db on behalf of Company that has the same initial letter. For that you can try the example below:

A. Create a new project and add a report.
2. Add TTable component on the report. Change the DatabaseName property to DBDEMOS, TableName become a Customer and IndexName ByCompany. Activate the chart by setting the Active property to True.
3. Add TQRGroup components that will be used as the header of the group. Change the Expression property to COPY (Table1.Company, 1, 1). Expression is used to extract the first character of the Company name.
4. Add TQRExpr components on the header band. The content property with a COPY Expression (Table1.Company, 1.1).

[Image: delphiqrgroup1.jpg]
Figure: Report by the group at design time

After that you can see the report by running the program directly or by right clicking on the report and select Preview.

[Image: delphiqrgroup2.jpg]
Figure: Report by the group at run time

From the figure above shows that the list of Company names grouped by the same first letter.
 
Adding a form to the DLL
 
Dynamic Link Library or DLL is a file that contains routines (procedures and functions) that can be called from the EXE file from a file or another DLL. By putting the routines in the DLL file (separate from the EXE file) then there are some advantages.First, the routines of a general nature can be shared by several applications at the same time and only needed one copy in memory or disk. You can arrange to have the routines contained in the DLL is loaded into memory only when needed. If not required then the DLL can be removed from memory. Thus applications that you can make more efficient use of memory.The second advantage, the application to be modular. You can update your application without having to update the EXE file. Thus you simply include the patches to the program without you having to include seluaruh application.Another advantage is the size of the EXE file into smaller because some program code is placed on the DLL file.
Creating a DLL file
To create a DLL file, how to select the menu File | New | DLL. You can save the project with ProyekDLL.dpr.
On a code editor you can look at the very top there is a clause library. This indicates that the project is a project being built DLL file. Next add the form from the menu File | New Form. Form must be added to the project, namely by selecting the menu projet | Add to Project and select the file unit of Form (in this example is FormDLL.pas). Examples of this DLL has two methods (one procedure and one function) whose function is to display the form. One using the Show and the other using ShowModal.
ShowFormDLL procedure; stdcall;beginfrmFormDLL: = TfrmFormDLL.Create (nil);frmFormDLL.Show;end;
The above procedure, it will first create the form. Nil parameters are used, because we do not know who the owner (owner) formnya. Furthermore the newly created form is displayed using the Show method.To display a form of capital is slightly different way.
ShowFormDLLModal function: integer; stdcall;beginfrmFormDLL: = TfrmFormDLL.Create (nil);Result: = frmFormDLL.ShowModal;end;
Difference between the above code and previous code is, that the above code is the function, whereas before the procedure code, the code above using ShowModal whereas the previous code to use Show. By using ShowModal you can know the result of a form of capital.In both the code we create a form but without ever did destroy, which can result in waste of memory (memory leaking). Therefore you need to destroy the form. One of the easiest is to use the OnClose event of the form and set TCloseAction be caFree.
TfrmFormDLL.FormClose procedure (Sender: TObject; var Action: TCloseAction);beginAction: = caFree;end;
The final step is to export procedure and function ShowFormDLLModal ShowFormDLL above so that it can be used or called by another program.
ExportsShowFormDLL,ShowFormDLLModal;
begin
end.
To make the above code into a DLL file you can select the menu Project | Build.
 
Create a flat effect
 
Sometimes we may want to make our program look a little different than usual. With these tips you can make the component checkbox, radiobutton and button becomes flat.
TForm1.Flatten procedure (theControl: TWinControl);vardwStyle: longint;begindwStyle: = GetWindowLong (theControl.handle, GWL_STYLE) or BS_FLAT;SetWindowLong (theControl.Handle, GWL_STYLE, dwStyle);end;
TForm1.FormCreate procedure (Sender: TObject);beginFlatten (Button1);Flatten (CheckBox1);Flatten (RadioButton1);end;
Here we use a function (function) Windows API, which is GetWindowLong the declaration as follows:
function GetWindowLong (hwnd: HWND; int: integer): integer;
GetWindowLong function is used to find information about a particular window. Window can we interpret here as the visual components such as checkboxes, radio buttons and so on.
The first parameter of the function GetWindowLong is a window handle of the component we are going to change a flat. The second parameter is a window of information we will take. In this case the second parameter is filled with GWL_STYLE which means we want to obtain the style of the window.
The second function that we use the SetWindowLong. That function is to change the attributes or style of a window.
To find out more detail about the Windows API function you can read in the help that is included when you install Delphi, on the Win32 Programmer's Reference.
As more code is as follows:
unit Unit1;
interface
usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
typeTForm1 = class (TForm)Edit1: TEdit;Button1: TButton;CheckBox1: TCheckBox;RadioButton1: TRadioButton;ListBox1: TListBox;FormCreate procedure (Sender: TObject);privateFlatten procedure (theControl: TWinControl);Flatten2 procedure (theControl: TEdit);{Private declarations}public{Public declarations}end;
varForm1: TForm1;
implementation
{$ R *. DFM}
TForm1.Flatten procedure (theControl: TWinControl);vardwStyle: longint;begindwStyle: = GetWindowLong (theControl.handle, GWL_STYLE) or BS_FLAT;SetWindowLong (theControl.Handle, GWL_STYLE, dwStyle);end;
TForm1.FormCreate procedure (Sender: TObject);beginFlatten (Button1);Flatten (CheckBox1);Flatten (RadioButton1);end;
end.
 
Disable menu and the Close button
 
A form usually has three buttons located on the title bar, ie the maximize, minimize, close.

To The tips below you can disable the button / menu close.

TForm1.FormCreate procedure (Sender: TObject);
var
hMenuHandle: HMENU;
begin
hMenuHandle: = GetSystemMenu (Form1.Handle, FALSE);
if (hMenuHandle <> 0) then DeleteMenu (hMenuHandle,
SC_CLOSE, MF_BYCOMMAND);
end;

The first step is to find the handle of the window menu (or the System menu or the Control menu), way is by using the function GetSystemMenu.

GetSystemMenu function (hWnd: HWND, bRevert: Boolean): HMENU;

The first parameter of the function is the handle of the window GetSystemMenu or form. In this example formnya name is Form1.
The second parameter is bRevert. If the value is True bRevert then the return value of function GetSystemMenu is NULL, otherwise if the value is False bRevert behind it is the handle of a copy of the menu window.

The next step is the "delete" menu item in the window by using the function DeleteMenu.

DeleteMenu function (hMenu: HMENU, uPosition: integer, uFlags: integer): Boolean

The first parameter is the handle of the window menu (which is a function of search results with GetSystemMenu).
The second parameter is the position or menu identifiers. If you fill out the third parameter to MF_BYCOMMAND the second parameter can be worth SC_CLOSE, SC_MOVE, and SC_SIZE. Conversely, if you fill the third parameter to MF_BYPOSITION then you can fill the second parameter to an integer value that represents the Close menu.

DeleteMenu function will return the value True if the deletion succeeded menu and returns the value False if it fails.
The second command below will get the same result:

DeleteMenu (hMenuHandle, 6, MF_BYPOSITION);
DeleteMenu (hMenuHandle, SC_CLOSE, MF_BYCOMMAND)
 
Add facilities to the skin at the application SXSkinComponents
 
Maybe you all have seen an application that uses the concept of skin, for example, Win Amp, WindowBlind, etc.. With the concept of skin, then the user can easily change the look of the program.

You may be inspired to create a program that is equipped with skin. How do I? The easiest way is to use component. One that is quite interesting and you can try is SXSkinComponents.

SXSkinComponents can be used for Delphi 6, Delphi 7, Delphi 2005, Delphi 2006, C + + Builder 6 and C + + Builder 2006 and the operating system Windows 98/ME/NT/2000/XP/2003.

In addition to the interesting features, one of the things that give value-added component of this is free!
 
DownloadClick Here
File Size: 3.3 Mb                       


Penulis : Unknown ~ Sebuah blog yang menyediakan berbagai macam informasi

Artikel Tutorial Delphi ini dipublish oleh Unknown pada hari Jumat, 09 Maret 2012. Semoga artikel ini dapat bermanfaat.Terimakasih atas kunjungan Anda silahkan tinggalkan komentar.sudah ada 0 komentar: di postingan Tutorial Delphi
 

0 komentar:

Posting Komentar