Aplikasi bisa dijalankan sekali saja


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

const
NamaAtom =’Program versi demo‘;

implementation

{$R *.DFM}

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 silakan‘ + #10 + #13 +
REGISTER !!‘);
Application.Terminate;
end;
end;

end.

TransCODE Software





Form Selalu Tampil Didepan


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.FormStyle:=fsStayOnTop;
end;

end.

TransCODE Software





Mengetahui Jumlah Hari Dalam Bulan


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Label3: TLabel;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
function
DaysPerMonth(AYear, AMonth: Integer): Integer;
function IsLeapYear(AYear: Integer): Boolean;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.IsLeapYear(AYear: Integer): Boolean;
begin
Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 = 0));
end;

function TForm1.DaysPerMonth(AYear, AMonth: Integer): Integer;
const
DaysInMonth: array[1..12] of Integer =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
Result := DaysInMonth[AMonth];
if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result); { leap-year Feb is special }
end;

procedure
TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text := IntToStr(DaysPerMonth(StrToInt(Edit2.Text), StrToInt(Edit1.Text)));
end;

end.

TransCODE Software



Mengecek Nama Host


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;

procedure Button1Click(Sender: TObject);
private
function IPAddrToName(IPAddr: String): String;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses winsock;

{$R *.dfm}

function TForm1.IPAddrToName(IPAddr: string): string;
var
SockAddrIn: TSockAddrIn;
HostEnt: PHostEnt;
WSAData: TWSAData;
begin
WSAStartup($101, WSAData);
try
SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
HostEnt := GetHostByAddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
if Assigned(HostEnt) then
Result := StrPas(Hostent^.h_name)
else
Result := ”;
finally
WSACleanup;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text :=IPAddrToName(Edit1.Text);
end;

end.

TransCODE Software

Mengecek IP Address


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
function LocalIP: string;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses
Winsock;

{$R *.dfm}

function
TForm1.LocalIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := ”;
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then
begin
Exit;
end;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do
begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := LocalIP;
end;

end.

TransCODE Software