Delphi Code - Close Others Application
procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: THandle;
begin
MyHandle:=FindWindow(nil, 'Delphi Help');
SendMessage(MyHandle, WM_CLOSE, 0, 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: THandle;
begin
MyHandle:=FindWindow(nil, 'Delphi Help');
SendMessage(MyHandle, WM_CLOSE, 0, 0);
end;
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
Bmp: TBitmap;
begin
if Field is TGraphicField then
begin
try
Bmp:=TBitmap.Create;
Bmp.Assign(Field);
DBGrid1.Canvas.StretchDraw(Rect, Bmp);
finally
Bmp.Free;
end
end
else
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
function LoadAndRunDLLProcedure(sDLL,sFunc : string):boolean;
type
TFunc_Start = procedure;
var
Func_Start : TFunc_Start;
hDll : THandle;
FuncPtr : TFarProc;
sMsg : string;
begin
Result := False;
hDll := LoadLibrary(PChar(sDLL));
if(hDll > 32)then
begin
FuncPtr := GetProcAddress(hDll,PChar(sFunc));
@Func_Start := FuncPtr;
if(nil <> @Func_Start)then
begin
Func_Start;
Result := True;
end
else
begin
sMsg := 'DLL entry point ' + sFunc + ' not found';
MessageBox(0, PChar( sMsg ), 'Error',MB_OK );
end;
FreeLibrary( hDll );
end
else
begin
sMsg := 'File ' + sDLL + ' not found';
MessageBox(0, PChar( sMsg ), 'Error',MB_OK );
end;
end;
function RunControlPanelApplet(sAppletFileName : string): integer;
begin
Result := WinExec(PChar('rundll32.exe shell32.dll,'+
'Control_RunDLL '+sAppletFileName),SW_SHOWNORMAL);
end;
access.cpl: Accessibility Properties
appwiz.cpl: Add/Remove Programs Properties
desk.cpl: Display Properties
intl.cpl: Regional Settings Properties
joy.cpl: Joystick Properties
main.cpl: Mouse Properties
mmsys.cpl: Multimedia Properties
modem.cpl: Modems Properties
sysdm.cpl: System Properties
timedate.cpl: Time/Date Properties
unit Konversi;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
function Convert(vString : String):String;
function ReadNumber(vString : String):string;
function GetNumber(vNum : Integer):String;
var
FValue : String;
FResult : String;
FCurrency : String;
implementation
function GetNumber(vNum : Integer):String;
begin
case vNum of
1 : Result := 'satu ';
2 : Result := 'dua ';
3 : Result := 'tiga ';
4 : Result := 'empat ';
5 : Result := 'lima ';
6 : Result := 'enam ';
7 : Result := 'tujuh ';
8 : Result := 'delapan ';
9 : Result := 'sembilan ';
0 : Result := '';
end;
end;
function ReadNumber(vString : String):string;
var level,len,j,i,vawal,awal,akhir,dgt : Integer;
str,bil,digit,lvl,temp2 : String;
begin
len := length(vString);
str := vString;
//cari level
level := len div 3;
if len mod 3 <> 0 then
level := level + 1;
//baca per 3 digit
for i := 1 to level do
begin
vawal := 0;
akhir := len - ((i-1)*3);
awal := akhir - 3 + 1;
if awal <= 0 then
awal := 1;
vString := copy(str,awal,akhir-awal+1);
if length(vString) < 3 then
akhir := length(vString)
else
akhir := 3;
awal := 1;
while akhir >= awal do
begin
dgt := akhir - awal + 1;
bil := GetNumber(StrToInt(vString[awal]));
case dgt of
1 : digit := '';
2 : digit := 'puluh ';
3 : digit := 'ratus ';
end;
//pengujian angka 10 dan 11
if dgt in [1,2] then
begin
if (StrToInt(vString[awal]+vString[awal+1]) >= 10) and
(StrToInt(vString[awal]+vString[awal+1]) < 20) then
begin
if (akhir - awal + 1 > 1) then
begin
if (StrToInt(vString[awal]) = 1) and
(StrToInt(vString[awal+1]) in [0,1]) then
bil := 'se'
else if (StrToInt(vString[awal]) = 1) and
(StrToInt(vString[awal+1]) > 1) then
bil := GetNumber(StrToInt(vString[awal+1]));
end;
if StrToInt(vString[akhir]) <> 0 then
begin
bil := bil + 'belas ';
digit := '';
vawal := awal + 1;
end
else
begin
vawal := awal + 1;
end;
end;
end;
if (((i = 2) and (awal=1) and (akhir = 1)) or
((akhir > 1) and (StrToInt(vString[1]) = 1) and
(dgt = 3))) and (StrToInt(vString[awal]) = 1) then
bil := 'se';
if (StrToInt(vString[awal]) = 0) then
digit := '';
Temp2 := Temp2 + bil + digit;
awal := awal + 1 + vawal;
vawal := 0;
end;
case i of
1 : lvl := '';
2 : lvl := 'ribu ';
3 : lvl := 'juta ';
4 : lvl := 'milliar ';
5 : lvl := 'trilliun ';
6 : lvl := 'billiun ';
end;
if StrToInt(vString) <> 0 then
begin
if (StrToInt(vString) = 1) and (i = 2) then
Temp2 := 'seribu '
else
Temp2 := Temp2 + lvl;
end;
Result := Temp2 + Result;
Temp2 := '';
end;
if (length(vString) = 1) and (vString = '0') then
Result := 'nol ';
end;
function Convert(vString : String):String;
var i,koma : Integer;
temp : string;
begin
koma := pos('.',vString);
if koma <> 0 then
begin
for i := 1 to 2 do
begin
if i = 1 then
begin
temp := copy(vString,1,koma-1);
Result := ReadNumber(temp);
Result := FResult + 'koma ';
end
else
begin
temp := copy(vString,koma+1,length(vString));
FResult := FResult + ReadNumber(temp);
end;
end;
end
else
Result := ReadNumber(vString);
Result := Result + 'rupiah';
end;
end.
UsesPenggunaan
... 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;
SetHeader(DBGrid1,'Biodata');
Contoh Isi IniFile
[BIODATA-JUMLAH]
JMLKOLOM=2
[BIODATA-HEADER]
NO_=No
___NIK____=NIK
uses Jpeg;
procedure Bmp2Jpeg(const BmpFileName, JpgFileName: string);
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Bmp.LoadFromFile(BmpFileName);
Jpg.Assign(Bmp);
Jpg.SaveToFile(JpgFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
procedure Jpeg2Bmp(const BmpFileName, JpgFileName: string);
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Jpg.LoadFromFile(JpgFileName);
Bmp.Assign(Jpg);
Bmp.SaveToFile(BmpFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
uses
Shlobj;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
SHAddToRecentDocs(SHARD_PATH, nil);
end;
function GetHardDiskSerial(const DriveLetter: Char): string;
var
NotUsed: DWORD;
VolumeFlags: DWORD;
VolumeInfo: array[0..MAX_PATH] of Char;
VolumeSerialNumber: DWORD;
begin
GetVolumeInformation(PChar(DriveLetter + ':\'),
nil, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
VolumeFlags, nil, 0);
Result := Format('Label = %s VolSer = %8.8X',
[VolumeInfo, VolumeSerialNumber])
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetHardDiskSerial('c'));
end;
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
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.
Berisi Lebih dari 300 Topik dan bulletin (technical information, alerts, contoh scripts dan contoh file) yang diterbitkan oleh Oracle Worldwide Customer Support.
Kekurangannya : Navigasinya kurang bagus, sehingga pencarian artikel agak sulit