+62 812-1171-5379 Fast Respond

Tips dan Trik Delphi

Shutdown Booting Logoff windows / Windows / Windows / Delphi 7 - XE
// reboot windows
      ExitWindowsEx(EWX_REBOOT,0);
      // shut down windows
      ExitWindowsEx(EWX_SHUTDOWN,0);
      // logoff andprompt for login
      ExitWindowsEx(EWX_LOGOFF,0);

Menguji agar tidak duplikat entry pada listbox / Form / Windows Android / Delphi 7 - XE
function StrIsInList(sl :TStrings; s : string; bCaseSensitive : boolean ) : boolean;
var
    n : integer;
begin
    Result := False;
    if (not bCaseSensitive) then
    s := LowerCase(s);
    for n := 0 to (sl.Count - 1) do
    begin
        if((bCaseSensitive and (s = LowerCase(sl.Strings[n]))) or(s = sl.Strings[n])) then
        begin
            Result := True;
            Exit;
        end;
    end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
     if (not StrIsInList(ListBox1.Items, Edit1.Text, True)) then
         ListBox1.Items.Add(Edit1.Text);
end;

Melihat nama komputer dari IP / Windows / Windows / Delphi 7 - XE
uses winsock; 
function IPAddrToName(IPAddr : string): string;
var
    SockAddrIn: TSockAddrIn;
    HostEnt: PHostEnt;
    WSAData: TWSAData;
begin
    WSAStartup($101, WSAData);
    SockAddrIn.sin_addr.s_addr:= inet_addr(PChar(IPAddr));
    HostEnt:= gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
    if HostEnt<>nil then
    begin
        result:=StrPas(Hostent^.h_name)
    end else
    begin
        result:='';
    end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
     // untuk tes lihat IP anda pada Lan
     Label1.Caption := IPAddrToName('192.168.0.2');
end;

Empty ricycle bin windows / Windows / Windows / Delphi 7 - XE
procedure EmptyRecycleBin;
const
    SHERB_NOCONFIRMATION = $00000001;
    SHERB_NOPROGRESSUI = $00000002;
    SHERB_NOSOUND = $00000004;
type
    TSHEmptyRecycleBin = function (Wnd: HWND;
    LPCTSTR: PChar;
    DWORD: Word): integer; stdcall;
var
    SHEmptyRecycleBin:TSHEmptyRecycleBin;
    LibHandle: THandle;
begin
    LibHandle := LoadLibrary(PChar('Shell32.dll'));
    if LibHandle <> 0 then
        @SHEmptyRecycleBin := GetProcAddress(LibHandle, 'SHEmptyRecycleBinA')
    else
    begin
        MessageDlg('Failed to load Shell32.dll.', mtError, [mbOK], 0);
        Exit;
    end;

if @SHEmptyRecycleBin <> nil then
    SHEmptyRecycleBin(Application.Handle, '', SHERB_NOCONFIRMATION or SHERB_NOPROGRESSUI or SHERB_NOSOUND);
    FreeLibrary(LibHandle);
    @SHEmptyRecycleBin := nil;
end;

Menampilkan mapdrive windows / Windows / Windows / Delphi 7 - XE

function GetNetworkDriveMappings(SList:TStrings):Integer;
var
    I:Char;
    ThePath:string;
    MaxNetPathLen:DWord;
begin
    SList.Clear;
    MaxNetPathLen:=MAX_PATH;
    SetLength(ThePath,MAX_PATH);
    for I := 'A' to 'Z' do
       if WNetGetConnection(PChar(''+I+':'),PChar(ThePath), MaxNetPathLen)=NO_ERROR then
          SList.Add(I+': '+ThePath);
    Result := SList.Count;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     GetNetworkDriveMappings(ListBox1.Items);
end;

                                        
Menampilkna dan menyembunyikan tasbar windows / Windows / Windows / Delphi 7 - XE
procedure hideTaskbar;
var
    wndHandle :THandle;
    wndClass : array[0..50] of Char;
begin
    StrPCopy(@wndClass[0], 'Shell_TrayWnd');
    wndHandle := FindWindow(@wndClass[0], nil);
    ShowWindow(wndHandle, SW_HIDE); // Sakla
end;

procedure showTaskbar;
var
  wndHandle :THandle;
  wndClass : array[0..50] of Char;
begin
    StrPCopy(@wndClass[0], 'Shell_TrayWnd');
    wndHandle := FindWindow(@wndClass[0], nil);
    ShowWindow(wndHandle, SW_RESTORE); // Göster
end;

Mengunci huruf pada keyboard / Tool / Windows / Delphi 7 - XE
function tombol(Key:Char):Char;
begin
    if (Key>='0') and (Key<='9') or (Key=#8) or (Key=#13) then
    begin
        Result:=Key;
    end else Result:=Chr(0);
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
     key := tombol(key);
end;

Menambahkan chekbox pada dialog pesan / Tool / Windows Android / Delphi 7 - XE
Function Pertanyaanku(isipertanyaan : String) : byte;
var
    AMsgDialog:TForm;
    ACheckBox: TCheckBox;
    Image, image2 : TImage;
begin
    AMsgDialog := CreateMessageDialog(isipertanyaan,  mtCustom, [mbYes, mbNo]);

    ACheckBox := TCheckBox.Create(AMsgDialog);
    with AMsgDialog do
    try
        AMsgDialog.Caption := 'Pertanyaan';
        AMsgDialog.BorderStyle := bsDialog;
        AMsgDialog.Color := clGreen;
        AMsgDialog.Font.Size := 10;
        AMsgDialog.Font.Color := clWhite;
        AMsgDialog.Height := 169;
        AMsgDialog.Width := 200;

        with ACheckBox do
        begin
            Parent := AMsgDialog;
            Caption := 'Jangan tampil lagi.';
            Top := 101;
            Width := 201;
            Left := 10;
        end;

        if (ShowModal = ID_YES) then
        begin
            Result := Id_yes;
            if ACheckBox.Checked then
            begin

            end else
            Begin

            End;
        end else
        Begin
             Result := ID_NO;
        End;

    finally
       ACheckBox.Free;
       Free;
    end;
end;

Enkripi dan Dekripsi sederhana / Tool / Windows Android / Delphi 7 - XE
function TForm1.Encrypt(S: string): string;
var
    Angka, i: Integer;
begin
    Result := ' ' + S;
    Angka := 32;
    for i := 1 to Length(S) do
    begin
        Angka := Angka + Ord(S[i]);
        while Angka > 126 do
              Angka := Angka - 95;
        end;
        Result[1] := Chr(Angka);

        for i := 2 to Length(Result) do
        begin
            Angka := Ord(Result[i]) + Ord(Result[i - 1]);
            while Angka > 126 do
                Angka := Angka - 95;
                Result[i] := Chr(Angka);
        end;
end;

function TForm1.Decrypt(S: string): string;
var
    Angka1, Angka2,
    Angka, i: Integer;
begin
    Result := S;
    for i := Length(S) downto 2 do
    begin
        Angka1 := Ord(S[i]);
        Angka2 := Ord(S[i - 1]);
        if Angka1 >= Angka2 then
        Angka := Angka1 - Angka2
        else
        Angka := (Angka1 + 95) - Angka2;
        while Angka < 32 do
        Angka := Angka + 95;
        Result[i] := Chr(Angka);
    end;
    Delete(Result, 1, 1);
end;

Meminimize semua windows aktif / Windows / Windows / Delphi 7 - XE
procedure TForm1.Minimize_all_windows;
var
    hnd : HWnd;
Begin
    hnd := handle;
    while hnd > 0 do
    begin
        if IsWindowVisible(hnd) then
           Postmessage(hnd, WM_SYSCOMMAND,SC_MINIMIZE,0);
        hnd := GetnextWindow(hnd, GW_HWNDNEXT);
    end;
End;