function Pertanyaanku(isi:String):word;
Begin
Application.RestoreTopMosts;
if MessageDlg(isi, mtConfirmation, [mbYes, mbNo],0) = mrYes Then
begin
Result := mryes;
end else
begin
Result := mrNo;
end;
Application.RestoreTopMosts;
end;
procedure Pesanku(Title, Text: string);
begin
MessageBoxEx(
0, PChar(Text), PChar(Title),
MB_OK or MB_TOPMOST or MB_SERVICE_NOTIFICATION, 0);
end;
//atau
function Pesanku(isi:String):word;
Begin
Application.RestoreTopMosts;
MessageDlg(isi, mtInformation, [mbOK], 0);
Application.RestoreTopMosts;
end;
function TForm1.IsNumber(pcString: PChar): Boolean;
begin
Result := False;
while pcString^ <> #0 do
begin
if not (pcString^ in ['0'..'9']) then
Exit;
Inc(pcString);
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsNumber(pchar(Edit1.Text)) then
begin
ShowMessage('Benar');
end else
begin
ShowMessage('Ditemukan ada huruf atau tanda baca lainnya');
end;
end;
var
Form1: TForm1;
Nums: array[1..10] of Word;
implementation
{$R *.dfm}
procedure SortShell(var aSort: array of Word);
var
iI, iJ, iK,
iSize: Integer;
wTemp: Word;
begin
iSize := High(aSort);
iK := iSize shr 1;
while iK > 0 do begin
for iI := 0 to iSize - iK do begin
iJ := iI;
while (iJ >= 0) and (aSort[iJ] > aSort[iJ + iK]) do begin
wTemp := aSort[iJ];
aSort[iJ] := aSort[iJ + iK];
aSort[iJ + iK] := wTemp;
if iJ > iK then
Dec(iJ, iK)
else
iJ := 0
end;
end;
iK := iK shr 1;
end;
end;
procedure AddToLB(const Nums: array of Word; LB: TListBox);
var
I: Integer;
begin
for I := Low(Nums) to High(Nums) do
begin
LB.Items.Add(IntToStr(Nums[I]));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
// memasukkan secara acak
Randomize;
for I := Low(Nums) to High(Nums) do
begin
Nums[I] := Random(50);
end;
AddToLB(Nums, ListBox1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Urutkan Angka
SortShell(Nums);
AddToLB(Nums, ListBox2);
end;
uses
WinTypes, ShellAPI;
procedure OpenObject(sObjectPath: string);
begin
ShellExecute(0, nil, PChar(sObjectPath ), nil, nil, SW_NORMAL);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenObject('C:\sidesamaju\instalasi.txt');
end;
Uses Registry;
function GetCPUSpeed : String;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create(KEY_QUERY_VALUE);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('HARDWARE\DESCRIPTION\System\CentralProcessor\0') then
begin
Result := Format('CPU Speed is %dMHz', [Reg.ReadInteger('~MHz')]);
Reg.CloseKey;
end;
finally
Reg.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetCPUSpeed;
end;
Uses PSapi;
function ProcessMemory: longint;
var
pmc: PPROCESS_MEMORY_COUNTERS;
cb: Integer;
begin
// Get the used memory for the current process
cb := SizeOf(TProcessMemoryCounters);
GetMem(pmc, cb);
pmc^.cb := cb;
if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then
Result:= Longint(pmc^.WorkingSetSize);
FreeMem(pmc);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := floattostr(ProcessMemory);
end;
// Konek dengan server ftp
idFTP1.Host := Edit_Host.Text;
idFTP1.Username := Edit_Name.Text;
idFTP1.Password := Edit_password.Text;
try
idFTP1.Connect;
finally
if idFTP1.Connected = True Then
Shape_Conect.Brush.Color := clLime;
end;
// Upload file image ke ftp
var
m : TStream;
f : TStream;
t : Cardinal;
Nama_folder,
Auxiliar :String;
Diretory : String;
contador : Integer;
begin
Auxiliar := '';
f := nil;
m := nil;
Memo_keterangan.Lines.Add('Original Directory:' + Diretory);
OpenDialog1.Filter := 'Files(*.*)|*.*';
if OpenDialog1.Execute then
begin
Nama_folder := OpenDialog1.FileName;
Memo_keterangan.Lines.Add ('Operation: local directory change');
Memo_keterangan.Lines.Add ('File directory: ' + GetCurrentDir);
Memo_keterangan.Lines.Add ('');
Nama_folder := AnsiStrRScan(PCHar(Nama_folder), '\');
for contador := 2 To StrLen(PCHar(Nama_folder)) do
Auxiliar := Auxiliar + Nama_folder [contador];
Nama_folder := Auxiliar;
try
Memo_keterangan.Lines.Add('Operation: Upload');
Memo_keterangan.Lines.Add ('Local file: ' + OpenDialog1.FileName);
Memo_keterangan.Lines.Add ('Recorded as: ' + Nama_folder);
f := TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
m := TMemoryStream.Create;
m.CopyFrom(f,f.Size);
m.Seek(0,0) ;
t := GetTickCount;
idFTP1.Put(m,Nama_folder);
Memo_keterangan.Lines.Add(Format('Time %d miliseconds',[GetTickCount - t]));
Memo_keterangan.Lines.Add(Format('Size %d bytes',[m.Size]));
Memo_keterangan.Lines.Add('');
finally
m.Free;
f.Free;
end;
end;
SetCurrentDir(Diretory);
Memo_keterangan.Lines.Add('Operation: change of local directory');
Memo_keterangan.Lines.Add ('Ddirectory after the operation:' + GetCurrentDir);
Memo_keterangan.Lines.Add ('');
end;
// Disknek dengan server ftp
try
idFTP1.Disconnect;
finally
if idFTP1.Connected = False then
Shape_Conectado.Brush.Color := clGray;
end;
// Konek dengan server ftp
idFTP1.Host := Edit_Host.Text;
idFTP1.Username := Edit_Name.Text;
idFTP1.Password := Edit_password.Text;
try
idFTP1.Connect;
finally
if idFTP1.Connected = True Then
Shape_Conect.Brush.Color := clLime;
end;
// Upload file image ke ftp
var
Stream: TStream;
begin
try
Stream:= TMemoryStream.Create;
if IdFTP1.Connected then
begin
if image1.Picture<>nil then
begin
Image1.Picture.Graphic.SaveToStream(Stream);
Stream.Position := 0;
IdFTP1.Put(Stream,StringReplace(DateTimeToStr(now)+'coba.jpg','/','',[rfReplaceAll]),true);
end;
end;
finally
stream.Free;
end;
end;
// Disknek dengan server ftp
try
idFTP1.Disconnect;
finally
if idFTP1.Connected = False then
Shape_Conectado.Brush.Color := clGray;
end;
Konek dengan server ftp
idFTP1.Host := Edit_Host.Text;
idFTP1.Username := Edit_Name.Text;
idFTP1.Password := Edit_password.Text;
try
idFTP1.Connect;
finally
if idFTP1.Connected = True Then
Shape_Conect.Brush.Color := clLime;
end;
Membaca file dari JPG ftp
var
MS : TMemoryStream;
Jpg: TJPEGImage;
begin
MS := TMemoryStream.Create;
Jpg := TJPEGImage.Create;
try
IdHTTP1.get('http://kursusdelphi.com/images/teacher1.jpg',MS);
Ms.Seek(0,soFromBeginning);
Jpg.LoadFromStream(MS);
Image1.Picture.Assign(Jpg);
finally
FreeAndNil(Jpg);
FreeAndNil(MS);
end;
end;
Membaca file dari png ftp
var
MS : TMemoryStream;
png: TPngImage;
begin
MS := TMemoryStream.Create;
png := TPngImage.Create;
try
IdHTTP1.get('http://kursusdelphi.com/images/logo.png',MS);
Ms.Seek(0,soFromBeginning);
png.LoadFromStream(MS);
Image1.Picture.Assign(png);
finally
FreeAndNil(png);
FreeAndNil(MS);
end;
end;
Disknek dengan server ftp
try
idFTP1.Disconnect;
finally
if idFTP1.Connected = False then
Shape_Conectado.Brush.Color := clGray;
end;