Selamat Datang !

Selamat Datang di Yus Waroeng Software ! Saya ucapkan terima kasih anda sudah masuk ke blog kami, dimana anda dapat mencari informasi Software Aplikasi yang anda butuhkan dan berbagi ilmu pemograman.
Cari Artikel

Showing posts with label DelphiTips. Show all posts
Showing posts with label DelphiTips. Show all posts

Saturday, March 29, 2008

Delphi Tips

yuswaroengsoftware Blog’s Delphi Tutorial

Contoh program menambahkan event.

nit ColorBox;

interface

uses
Classes, Graphics, Controls, Windows;

type
TOnLeftBoxClick = procedure(Sender: TObject) of object;
TOnRightBoxClick = procedure(Sender: TObject) of object;
TColorBox = class(TGraphicControl)
private
FRgnL, FRgnR: TRect;
FOnLeftBoxSelect: TOnLeftBoxClick;
FOnRightBoxSelect: TOnRightBoxClick;
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnBoxLClick: TOnLeftBoxClick
read FOnLeftBoxSelect write FOnLeftBoxSelect;
property OnBoxRClick: TOnRightBoxClick
read FOnRightBoxSelect write FOnRightBoxSelect;
end;

procedure Register;

implementation

constructor TColorBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height:=33;
Width:=61;
end;

destructor TColorBox.Destroy;
begin
inherited Destroy;
end;

procedure TColorBox.Paint;
var cp: Integer;
begin
with Canvas do
begin
Pen.Color:=clBtnHighlight;
MoveTo(0, Height-1); LineTo(0, 0); LineTo(Width-1, 0);
Pen.Color:=clBtnShadow;
LineTo(Width-1, Height-1); LineTo(1, Height-1);
end;

cp:=Width div 2;
{–left area–}
FRgnL.TopLeft:=Point(4, 4);
FRgnL.BottomRight:=Point(cp-1, Height-3);
{–right box–}
FRgnR.TopLeft:=Point(cp+1, 4);
FRgnR.BottomRight:=Point(Width-4, Height-4);

{–left box–}
Canvas.Brush.Color:=$00B7CAF7;
Canvas.Rectangle(4, 4, cp-1, Height-4);
{–right box–}
Canvas.Brush.Color:=$00F4D5C1;
Canvas.Rectangle(cp+1, 4, Width-4, Height-4);
end;

procedure TColorBox.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var p: TPoint;
begin
inherited MouseUp(Button, Shift, X, Y);
if Button <> mbLeft then Exit;
p:=Point(X, Y);
if PtInRect(FRgnL, p) then {–left box–}
begin
if Assigned(FOnLeftBoxSelect) then FOnLeftBoxSelect(Self);
Invalidate;
end
else if PtInRect(FRgnR, p) then {–right box–}
begin
if Assigned(FOnRightBoxSelect) then FOnRightBoxSelect(Self);
Invalidate;
end;
end;

procedure Register;
begin
RegisterComponents(’Demo’, [TColorBox]);
end;

end.

prosedur pembatasan gerakan mouse.

procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
R:=Rect(Left, Top, Left+Width, Top+Height);
if GerakDalamForm then ClipCursor(@R)
else ClipCursor(@NilaiDefault);
end;

Cara Gampang Mengakses Array

var
MyArray : Array[2..11] of integer;
Position : integer;
begin
for Position := Low(MyArray) to High(MyArray) do
MyArray[Position] := 0;
end;

Read More (Baca Selanjutnya)......

Wednesday, March 19, 2008

Delphi Tips & Trick


  • 1.Ganti warna font secara acak dengan fungsi random..ternyata simpel dan font jadi cantik.
Langkah - Langkahnya :
Pertama Siapkan 1label,1timer (atur interval timer=200)

procedure TForm1.Timer1Timer(Sender: TObject);
var
x : integer;
begin
label1.Font.Color:=random(x);
end;

NB: "bisa juga buat ngacak posisi object dalam sebuah form..bahkan buat kursor mouse gerak sendiri kayak Virus gitu" Twisted Evil

  • 2.Menutup Aplikasi Dengan Animasi
{$R *.dfm}
// Autor: Yusfian Gunawan

var
tutup: Boolean;
i: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
tutup := True;
timer1.Enabled := False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
reg1, reg2: hrgn;
begin
if tutup = True then
begin
i := i + 10;
reg1 := CreateRoundRectRgn(0 + i, 0 + i, Width - i, Height - i, 20, 20);
SetWindowRgn(Handle, reg1, True);
end;

if i >= Width then
begin
tutup := False;
i := 1;
end;

if tutup = False then
begin
i := i + 10;
reg1 := CreateRectRgn(0, 0, (Width div 2) - i, Height);
reg2 := CreateRectRgn((Width div 2) + i, 0, Width, Height);
CombineRgn(reg1, reg1, reg2, rgn_or);
SetWindowRgn(Handle, reg1, True);
if i >= Width div 2 then
begin
tutup := True;
i := 1;
end;
end;

end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
reg1: hrgn;
begin
i := 1;
timer1.Enabled := True;
if MessageDlg('Anda Yakin Akan Keluar ?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
CanClose := True
else
begin
CanClose := False;
timer1.Enabled := False;
reg1 := CreateRoundRectRgn(0, 0, Width, Height, 0, 0);
SetWindowRgn(Handle, reg1, True);
end;

end;

end.

  • 3.Program Hanya Bisa Dujalankan Satu kali
procedure TForm1.FormCreate(Sender: TObject);
var
atom : integer;
begin
if GlobalFindAtom(NamaAtom) = 0 then
atom := GlobalAddAtom(NamaAtom)
else
begin
ShowMessage('Program ini hanya dapat dijalankan sekali dalam satu sesi Windows' + #10 + #13 +
'Untuk menjalankan program ini lagi, restart komputer Anda atau silahkan' + #10 + #13 +
'REGISTER !!');
Application.Terminate;
end;
end;

end.

Read More (Baca Selanjutnya)......

Komentar Terbaru