private
{ Private declarations }
InsertOn : bool;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_INSERT) and (Shift = []) then
Inserton := not InsertOn;
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if ((Memo1.SelLength = 0) and (not InsertOn)) then
Memo1.SelLength := 1;
end;
procedure TForm1.SetHorizontalScrollBar(lb :TListBox);
var
i, MaxWidth: integer;
begin
MaxWidth := 0;
for i := 0 to lb.Items.Count - 1 do
if MaxWidth < lb.Canvas.TextWidth(lb.Items[i]) then
MaxWidth := lb.Canvas.TextWidth(lb.Items[i]);
SendMessage(lb.Handle, LB_SETHORIZONTALEXTENT, MaxWidth + 5, 0);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
SetHorizontalScrollBar(ListBox1);
end;
procedure ShowDesktop(const YesNo : boolean);
var h : THandle;
begin
h := FindWindow('ProgMan', nil);
h := GetWindow(h, GW_CHILD);
if YesNo = True then
ShowWindow(h, SW_SHOW)
else
ShowWindow(h, SW_HIDE);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowDesktop(True);
end;
procedure SaveStringToFile(const aFilename: TFilename; const aString: string);
var
SL: TStringList;
begin
SL := TStringList.Create; // call outside the try
try
SL.Text := aString;
SL.SaveToFile(aFilename);
finally
SL.Free // will be called no matter what happens above
end;
end;
private
{ Private declarations }
public
{ Public declarations }
Function hitung : longint; overload;
Function hitung(a, b : integer) : longint; overload;
end;
var
Form1: TForm1;
c, d : integer;
implementation
{$R *.dfm}
Function TForm1.hitung : longint;
Begin
result := c + d;
End;
Function TForm1.hitung(a, b : integer) : longint;
Begin
result := a + b;
End;
end.
procedure TForm1.ShowHint(Sender: TObject);
begin
StatusBar1.SimpleText := Application.Hint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnHint := ShowHint;
end;
private
{ Private declarations }
public
{ Public declarations }
Edits: array[0..5] of TEdit;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to 5 do
begin
Edits[i] := TEdit.Create(Self);
with Edits[i] do
begin
Parent := Self;
SetBounds(10, 10 + i*50, 200, 40);
Tag := i; //each control should remember its index
OnChange := EditChange; //same event handler for all controls
end;
end;
end;
procedure TForm1.EditChange(Sender: TObject);
var
i: integer;
begin
i := TEdit(Sender).Tag;
ShowMessage(Format('Anda menekan Edit[%d]',[i]));
end;
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
panel1.Perform(WM_SYSCOMMAND, $f012, 0)
end;
procedure TForm1.SetTransparent(hWnd: longint; value: byte);
var
style: integer;
begin
style := GetWindowLong(hWnd, GWL_EXSTYLE);
if value < 255 then
begin
style := style Or WS_EX_LAYERED;
SetWindowLong(hWnd, GWL_EXSTYLE, style);
SetLayeredWindowAttributes(hWnd, 0, value, LWA_ALPHA);
end else
begin
style := style xor WS_EX_LAYERED;
SetWindowLong(hWnd, GWL_EXSTYLE, style);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetTransparent(Handle, 200);
end;
procedure TForm1.SetTopmost(form: TForm; topmost: boolean);
begin
if topmost then
SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
else
SetWindowPos(form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetTopmost(form1, true);
end;