Ferry Setiawan

Thursday, June 08, 2006

Set Header Caption With IniFile


Uses
... IniFiles;


procedure SetHeader(Grid: TDBGrid; Table: String);
var vIniFile : TIniFile;
i : integer;
Str : String;
DSource : TDataSource;
begin
vIniFile := TIniFile.Create('C:\Coba.Ini');
Str := vIniFile.ReadString(UPPERCASE(Table)+
'-JUMLAH','JMLKOLOM','0');
DSource := Grid.DataSource;
for i := 0 to StrToInt(Str)-1 do
begin
Grid.Columns.Add;
Grid.Columns[i].FieldName :=
DSource.DataSet.Fields[i].FieldName;
Grid.Columns[i].Title.Caption :=
vIniFile.ReadString(UPPERCASE(Table)+
'-HEADER',Grid.Columns[i].FieldName,'');
end;
end;




Penggunaan
SetHeader(DBGrid1,'Biodata');

Contoh Isi IniFile

[BIODATA-JUMLAH]
JMLKOLOM=2

[BIODATA-HEADER]
NO_=No
___NIK____=NIK



Keterangan :
BIODATA adalah nama table
BIODATA-JUMLAH adalah jumlah kolom yang ingin ditampilkan
BIODATA-HEADER adalah nama kolom dan caption yang akan ditampilkan

Thursday, June 01, 2006

Disable Keyboard Functions

Penggunaan
if Key = VK_RETURN then
--> statement...
Letakkan di Event KEYDOWN atau object lainnya, Mis TEdit,TComboBox, dll
untuk Form, Set Property KeyPreview menjadi True

Daftar Virtual Key yang lain
----------------------------------------------------------------------------------
VK_LBUTTON Left mouse button
VK_RBUTTON Right mouse button
VK_CANCEL Control+Break
VK_MBUTTON Middle mouse button
VK_BACK Backspace key
VK_TAB Tab key
VK_CLEAR Clear key
VK_RETURN Enter key
VK_SHIFT Shift key
VK_CONTROL Ctrl key
VK_MENU Alt key
VK_PAUSE Pause key
VK_CAPITAL Caps Lock key
VK_KANA Used with IME
VK_HANGUL Used with IME
VK_JUNJA Used with IME
VK_FINAL Used with IME
VK_HANJA Used with IME
VK_KANJI Used with IME
VK_CONVERT Used with IME
VK_NONCONVERT Used with IME
VK_ACCEPT Used with IME
VK_MODECHANGE Used with IME
VK_ESCAPE Esc key
VK_SPACE Space bar
VK_PRIOR Page Up key
VK_NEXT Page Down key
VK_END End key
VK_HOME Home key
VK_LEFT Left Arrow key
VK_UP Up Arrow key
VK_RIGHT Right Arrow key
VK_DOWN Down Arrow key
VK_SELECT Select key
VK_PRINT Print key (keyboard-specific)
VK_EXECUTE Execute key
VK_SNAPSHOT Print Screen key
VK_INSERT Insert key
VK_DELETE Delete key
VK_HELP Help key
VK_LWIN Left Windows key (Microsoft keyboard)
VK_RWIN Right Windows key (Microsoft keyboard)
VK_APPS Applications key (Microsoft keyboard)
VK_NUMPAD0 0 key (numeric keypad)
VK_NUMPAD1 1 key (numeric keypad)
VK_NUMPAD2 2 key (numeric keypad)
VK_NUMPAD3 3 key (numeric keypad)
VK_NUMPAD4 4 key (numeric keypad)
VK_NUMPAD5 5 key (numeric keypad)
VK_NUMPAD6 6 key (numeric keypad)
VK_NUMPAD7 7 key (numeric keypad)
VK_NUMPAD8 8 key (numeric keypad)
VK_NUMPAD9 9 key (numeric keypad)
VK_MULTIPLY Multiply key (numeric keypad)
VK_ADD Add key (numeric keypad)
VK_SEPARATOR Separator key (numeric keypad)
VK_SUBTRACT Subtract key (numeric keypad)
VK_DECIMAL Decimal key (numeric keypad)
VK_DIVIDE Divide key (numeric keypad)
VK_F1 F1 key
VK_F2 F2 key
VK_F3 F3 key
VK_F4 F4 key
VK_F5 F5 key
VK_F6 F6 key
VK_F7 F7 key
VK_F8 F8 key
VK_F9 F9 key
VK_F10 F10 key
VK_F11 F11 key
VK_F12 F12 key
VK_F13 F13 key
VK_F14 F14 key
VK_F15 F15 key
VK_F16 F16 key
VK_F17 F17 key
VK_F18 F18 key
VK_F19 F19 key
VK_F20 F20 key
VK_F21 F21 key
VK_F22 F22 key
VK_F23 F23 key
VK_F24 F24 key
VK_NUMLOCK Num Lock key
VK_SCROLL Scroll Lock key
VK_LSHIFT Left Shift key (only used with GetAsyncKeyState and GetKeyState)
VK_RSHIFT Right Shift key (only used with GetAsyncKeyState and GetKeyState)
VK_LCONTROL Left Ctrl key (only used with GetAsyncKeyState and GetKeyState)
VK_RCONTROL Right Ctrl key (only used with GetAsyncKeyState and GetKeyState)
VK_LMENU Left Alt key (only used with GetAsyncKeyState and GetKeyState)
VK_RMENU Right Alt key (only used with GetAsyncKeyState and GetKeyState)
VK_PROCESSKEY Process key
VK_ATTN Attn key
VK_CRSEL CrSel key
VK_EXSEL ExSel key
VK_EREOF Erase EOF key
VK_PLAY Play key
VK_ZOOM Zoom key
VK_NONAME Reserved for future use
VK_PA1 PA1 key
VK_OEM_CLEAR Clear key

Optimizing Your Delphi Application

1. Keep your code clean. This will make it easier to read and understand the code. Use meaningful variable and constant names. For example sMessage, sName for String variables, iCounter for integer variables. Constants could all be uppercase: iRATE for integer constant and sWARNING for a string constant. For components: don't ever use the standard naming: Button1, Edit1, Combo1. The more components you have the more time it'll take to find the one you want.


2. Leave the {$O+} (or {$Optimization On}) compiler directive on. With this directive, Delphi compiler produces more efficient code. Sometimes, debugging is more difficult with optimization enabled: you cannot set a breakpoint on a statement if the optimizer determines that the statement serves no purpose. All optimizations performed by Delphi's Object Pascal compiler are guaranteed not to alter the meaning of a program.


3. You may want to compile your programs with run-time packages. This can save a lot on size when you have a lot of programs that use the same libraries. Unfortunately, when distributing your application you will need to deploy dll's as well.


4. Don't create all the forms on program startup (they are created by default) because this will make your program load slower and require a lot more memory. Instead you should use dynamically created forms.


5. Use Windows API functions instead of writing your own functions to do the same task. They are usually faster and you will save size too.


6. When including images in your programs try to optimize them first. When including BMP files be sure that the file has the exact size you need else crop it and make sure that you don't have a 16 color image saved in 64K color mode. When including GIF images you may optimize their color palete with special tools. When including JPEG images you may want to use image compression. Convert JPEG image that contains 256 or less colors to a GIF image - they are much smaller.


7. When your are going to use only one or two functions or procedures from a unit and you have the unit's source code don't include the whole unit in the uses section but insert only the functions you are going to use into the code. This will prevent Delphi to add to executable all the routines from that unit.


8. Instead of using non-visible components it's usually better to include the code in your program. There's no need in using a component that displays Windows browse directory dialog when it's really just a few lines of code.


9. If you have a time-critical function (important loops) you should be very careful. What seems fast on your computer may not be as fast on other PC's. Here you should use as small code as possible and make it fast. You may want to use assembler (always comment it).


10. Nearly all programs have to do some rudimentary calculations of some kind. Simplifying your formulas to use faster functions is a very typical optimization opportunity. Knowing how data bandwidth and calculations perform relative to each other is also very important. For example, using tables to avoid certain recalculations is often a good idea (values for Sine and Cosine). Always try to use more efficient algorithms to replace an inefficient one are: a Binary Search to replace a Linear Search.