Merefresh dekstop / Windows / Windows / Delphi 7 - XE
uses ShlObj;
procedure RefreshDesktop1;
begin
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
RefreshDesktop1;
end;
<>/pre
Menampilkan semua hint pada statusbar / Tool / Windows / Delphi 7 - XE
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnHint := MyHint;
ShowHint := True;
Button1.Hint := 'Untuk menyimpan data';
Button2.Hint := 'Koreksi data dan klik Simpan';
Button3.Hint := 'Cetak pada printer';
Edit1.Hint := 'Kode barang';
end;
procedure TForm1.MyHint(Sender: TObject);
begin
StatusBar1.SimpleText := Application.Hint;
end;
Membuat splash program / Form / Windows / Delphi 7 - XE
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {FSplash};
{$R *.res}
begin
Application.Initialize;
// tambahkan perintah dibawah ini
Fsplash := TFSplash.Create(Application);
Fsplash.Show;
Fsplash.Update;
// Akhir tambahkan perintah dibawah ini
Application.CreateForm(TForm1, Form1);
// Tambahkan pula dibawah ini
Fsplash.Close;
Application.Run;
end.
// pada project option pilih nama FSplash dipindah ke available form
Membuat style warna dialog / Form / Windows / Delphi 7 - XE
var
f: TForm;
begin
f := Dialogs.CreateMessageDialog('HELLOWORLD', dialogs.mtInformation, dialogs.mbOKCancel);
f.Color := clBlue;
f.Font.Color := clLime;
if f.ShowModal = mrOk then
ShowMessage('OK ditekan')
else
ShowMessage('Cancel ditekan.')
end;
Mengganti caption dialog / Form / Windows / Delphi 7 - XE
function MyMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; Captions: array of string): Integer;
var
aMsgDlg: TForm;
i: Integer;
dlgButton: TButton;
CaptionIndex: Integer;
begin
aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons);
captionIndex := 0;
for i := 0 to aMsgDlg.ComponentCount - 1 do
begin
if (aMsgDlg.Components[i] is TButton) then
begin
dlgButton := TButton(aMsgDlg.Components[i]);
if CaptionIndex > High(Captions) then Break;
dlgButton.Caption := Captions[CaptionIndex];
Inc(CaptionIndex);
end;
end;
Result := aMsgDlg.ShowModal;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if MyMessageDialog('Berapa banyak', mtConfirmation, mbOKCancel, ['1', '2']) = mrOk then
ShowMessage('"1" Diklik')
else
ShowMessage('"2" Diklik');
end;
Memberi warna button pada toolbar / Form / Windows / Delphi 7 - XE
procedure TForm1.ToolBar1CustomDrawButton(Sender: TToolBar;
Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
Sender.Canvas.Brush.Color := clAqua;
Sender.Canvas.Rectangle(Button.BoundsRect);
end;
Keterangan : tambahkan toolbar dan klik kanan pada toolbar tersebut pilih new button, buat sebanyak 5 tombol
Membuat password acak / Tool / Windows Android / Delphi 7 - XE
function RandomPassword(PLen: Integer): string;
var
str: string;
begin
Randomize;
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
Result := '';
repeat
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = PLen)
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.text := RandomPassword(10);
end;
Menguji kebenaran angka atau nilai / Tool / Windows / Delphi 7 - XE
function IsStrANumber(const S: string): Boolean;
var
P: PChar;
begin
P := PChar(S);
Result := False;
while P^ <> #0 do
begin
if not (P^ in ['0'..'9']) then Exit;
Inc(P);
end;
Result := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if IsStrANumber('1234567890A')= true Then
ShowMessage('Benar') else
ShowMessage('Salah');
end;
Menguji numlock capsslock scroll lock aktif / Tool / Windows / Delphi 7 - XE
function GetExtendedKeys(shift:TShiftState):string;
var Ctlkeys:string;
begin
Ctlkeys:=' ';
if ssShift in shift then
begin
if getkeystate(VK_LShift) < 0 then
ctlkeys := 'Shift{Left}+'
else if getkeystate(VK_RShift) < 0 then
ctlkeys := 'Shift{Right}+';
end;
if ssAlt in shift then
begin
if getkeystate(VK_LMenu) < 0 then
ctlkeys := ctlkeys+'Alt{Left}+'
else if getkeystate(VK_RMenu) < 0 then
ctlkeys := ctlkeys+'Alt{Right}+';
end;
if ssCtrl in shift then
begin
if getkeystate(VK_LControl) < 0 then
ctlkeys := ctlkeys+'Ctrl{Left}+'
else if getkeystate(VK_RControl) < 0 then
ctlkeys := ctlkeys+'Ctrl{Right}+';
end;
delete(ctlkeys,length(ctlkeys),1);
result := ctlkeys;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
msg : string;
keyname, ctlkeys : string;
begin
msg:='';
ctlkeys := GetExtendedKeys(Shift);
if key = vk_capital then
begin
if 1 and getkeystate(key)>0 then
capslock.caption:='ON'
else
capslock.caption:='OFF';
end;
if key=vk_Numlock then
begin
if 1 and getkeystate(key)>0 then
numlock.caption:='ON'
else
numlock.caption:='OFF';
end;
if key=vk_Scroll then
begin
if 1 and getkeystate(key)>0 then
ScrollLock.caption:='ON'
else ScrollLock.caption:='OFF';
end;
key:=0;
end;
Memberi event pada create komponen / Form / Windows / Delphi 7 - XE
Var
Tombol : TButton;
procedure TForm1.Buttonme(Sender: TObject);
begin
ShowMessage(Inttostr(i));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Tombol := TButton.Create(form1);
Tombol.Parent := form1;
Tombol.Left := 100;
Tombol.Top := 100;
Tombol.OnClick := Buttonme;
End;