+62 812-1171-5379 Fast Respond

Tips dan Trik Delphi - Tool

Set Cookies dengan unigui / Tool / Windows / Delphi 7 - XE
Function TFPelanggan.Setcookies(nama_var : String; isi_var: String) : String;
begin
     UniApplication.Cookies.SetCookie(nama_var, isi_var, Jam_akhir_cookies);
end;

Function TFPelanggan.Loadcookies(nama_var : String) : String;
begin
     result := UniApplication.Cookies.Values[nama_var];
end;

Cara menjalankan Unigui di XAMPP / Tool / Windows / Delphi 7 - XE
Buka file Httpd.Config pada folder XAMPP atau pada control panel klik config dan pilih Httpd.Config.

Tambahkan index.dll pada seperti module

DirectoryIndex index app.dll index.php index.pl index.cgi index.asp index.shtml index.html index.htm \ default.php default.pl default.cgi default.asp default.shtml default.html default.htm \ home.php home.pl home.cgi home.asp home.shtml home.html home.htm

Pada pagian bawahnya (Handler) samakan seperti ini

# # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # AddHandler cgi-script .cgi .pl .asp AddHandler isapi-handler .dll # For type maps (negotiated resources): #AddHandler type-map var
Penggunaan Define Android dan Windows / Tool / Windows Android / Delphi 7 - XE
{$IF DEFINED (ANDROID) OR DEFINED(IOS)}
    // Statement / Perintah Sintak Android atau IOS
{$ELSEIF Defined(MSWINDOWS)}
    // Statement / Perintah Dekstop
{$ENDIF}

Contoh penerapannya :
procedure TFMain.FDConnection1BeforeConnect(Sender: TObject);
begin
     FDConnection1.DriverName := 'SQLite';
     {$IF DEFINED (ANDROID) OR DEFINED(IOS)}
     	  FDConnection1.Params.Values['Database'] := TPath.Combine(TPath.GetDocumentsPath, 'welijo.db');
     {$ELSEIF Defined(MSWINDOWS)}
	  FDConnection1.Params.Values['Database'] := System.SysUtils.GetCurrentDir + '\welijo.db';
     {$ENDIF}
end;


Menampilkan pasaran jawa / weton / Tool / Windows Android / Delphi 7 - XE
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button2: TButton;
    DateTimePicker1: TDateTimePicker;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function HariPasaran(tgl:TDateTime):string;
  end;

var
  Form1: TForm1;
  NilaiHari, NilaiWeton : byte;

implementation

{$R *.dfm}

function Pasaran(const DateTime: TDateTime): Word;
begin
  Result := DateTimeToTimeStamp(DateTime).Date mod 5 + 1;
end;

function HariIni(tgl:TDateTime):string;
begin
    case DayOfWeek(Tgl) of
        1 : Begin
                 Result := 'MINGGU';
                 NilaiHari := 5;
            End;
        2 : Begin
                 Result := 'SENIN';
                 NilaiHari := 4;
            End;
        3 : Begin
                 Result := 'SELASA';
                 NilaiHari := 3;
            End;
        4 : Begin
                 Result := 'RABU';
                 NilaiHari := 7;
            End;
        5 : Begin
                 Result := 'KAMIS';
                 NilaiHari := 8;
            End;
        6 : Begin
                 Result := 'JUMAT';
                 NilaiHari := 6;
            End;
        7 : Begin
                 Result := 'SABTU';
                 NilaiHari := 9;
            End;
    end;
end;

function TForm1.HariPasaran(tgl:TDateTime):string;
begin
    case Pasaran(Tgl) of
          1 : Begin
                   Result := 'Legi';
                   NilaiWeton := 5;
              End;
          2 : Begin
                   Result := 'Pahing';
                   NilaiWeton := 9;
              End;
          3 : Begin
                   Result := 'Pon';
                   NilaiWeton := 7;
              End;
          4 : Begin
                   Result := 'Wage';
                   NilaiWeton := 4;
              End;
          5 : Begin
                   Result := 'Kliwon';
                   NilaiWeton := 8;
              End;
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     Memo1.Clear;
     Memo1.Lines.Add(HariIni(DateTimePicker1.Date) +' + '+ inttostr(NilaiHari));
     Memo1.Lines.Add(HariPasaran(DateTimePicker1.Date) +' + '+ inttostr(NilaiWeton));
     Memo1.Lines.Add('Total = ' + inttostr(NilaiHari + NilaiWeton));
end;

end.



Membuat label url / Tool / Android / Delphi 7 - XE
Silahkan membuat unit seperti dibawah ini :

unit u_urlopen;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
{$IF Defined(IOS)}
  macapi.helpers, iOSapi.Foundation, FMX.helpers.iOS;
{$ELSEIF Defined(ANDROID)}
Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Net,
   Androidapi.JNI.App,
  Androidapi.helpers;
{$ELSEIF Defined(MACOS)}
Posix.Stdlib;
{$ELSEIF Defined(MSWINDOWS)}
Winapi.ShellAPI, Winapi.Windows;
{$ENDIF}

type
  tUrlOpen = class
    class procedure Open(URL: string);
  end;

implementation

class procedure tUrlOpen.Open(URL: string);
{$IF Defined(ANDROID)}
var
  Intent: JIntent;
{$ENDIF}
begin
    {$IF Defined(ANDROID)}
      Intent := TJIntent.Create;
      Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      Intent.setData(StrToJURI(URL));
      tandroidhelper.Activity.startActivity(Intent);
      // SharedActivity.startActivity(Intent);
    {$ELSEIF Defined(MSWINDOWS)}
      ShellExecute(0, 'OPEN', PWideChar(URL), nil, nil, SW_SHOWNORMAL);
    {$ELSEIF Defined(IOS)}
      SharedApplication.OpenURL(StrToNSUrl(URL));
    {$ELSEIF Defined(MACOS)}
      _system(PAnsiChar('open ' + AnsiString(URL)));
    {$ENDIF}
end;

end.

Dan untuk memanggilnya :
Jangan lupa pada label1 pilih properties dan cari hittest di centang

Uses u_urlopen;

procedure TForm1.Label2Click(Sender: TObject);
begin
     tUrlOpen.Open('https://www.kursusdelphi.com/tips-dan-trik-delphi');
end;

Membuat layar standby / Tool / Windows / Delphi 7 - XE
procedure TForm1.Button1Click(Sender: TObject);
begin  
     SendMessage(Application.Handle,WM_SYSCOMMAND,SC_MONITORPOWER,2);
end;

Menyimpan log file txt / Tool / Windows / Delphi 7 - XE
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function AppendOrWriteTextToFile(FileName : TFilename; WriteText : string): boolean;
var
  f : Textfile;
begin
    Result := False;
    AssignFile(f, FileName);
    try
        if FileExists(FileName) = False then
            Rewrite(f)
        else
        begin
            Append(f);
        end;
        Writeln(f, WriteText);
        Result := True;
    finally
        CloseFile(f);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  dir, log : string;
begin
    dir := ExtractFilePath(Application.Exename);
    log := 'Button di klik pada : ' + DateTimeToStr(now);
    AppendOrWriteTextToFile(dir + '\logfile.txt', log);
end;

end.


Menampilkan format kalender indonesia / Tool / Windows / Delphi 7 - XE
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    DateTimePicker1: TDateTimePicker;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  namaBulan: array[1..12] of string =
    ( 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');

implementation

{$R *.dfm}

Procedure ReplaceLongMonthNamesWithIndonesian;
var i : integer;
begin     
    for i:=1 to High(namaBulan) do
    Begin
	LongMonthNames[i] := namaBulan[i];
    End;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
     ReplaceLongMonthNamesWithIndonesian;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     edit1.text := FormatDateTime('dd MMMM yyyy', DateTimePicker1.Date);
end;

end.


Insert delete baris Stringgrid / Tool / Windows / Delphi 7 - XE
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TStringGridHack = class(TStringGrid)
  protected
    procedure DeleteRow(ARow: Longint); reintroduce;
    procedure InsertRow(ARow: Longint);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TStringGridHack.DeleteRow(ARow: Longint);
var
  i : integer;
begin
     i := ARow;
     For i := arow to RowCount - 1  do
     Begin
          Rows[i].Assign(Rows[i+1]);
     End;
     RowCount := RowCount - 1;
end;

procedure TStringGridHack.InsertRow(ARow: Longint);
var
  GemRow: Integer;
begin
    GemRow := Row;
    while ARow < FixedRows do
    Inc(ARow);

    RowCount := RowCount + 1;
    MoveRow(RowCount - 1, ARow);
    Row := GemRow;
    Rows[Row].Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     StringGrid1.Cells[0,0] := 'NO';
     StringGrid1.Cells[1,0] := 'NAMA';
     StringGrid1.Cells[2,0] := 'ALAMAT';
     StringGrid1.Cells[3,0] := 'TELP';

     StringGrid1.Cells[0,1] := '1';
     StringGrid1.Cells[1,1] := 'Tonny Malang';
     StringGrid1.Cells[2,1] := '1';
     StringGrid1.Cells[3,1] := '1';

     StringGrid1.Cells[0,2] := '2';
     StringGrid1.Cells[1,2] := 'Fathon';
     StringGrid1.Cells[2,2] := '2';
     StringGrid1.Cells[3,2] := '2';

     StringGrid1.Cells[0,3] := '3';
     StringGrid1.Cells[1,3] := 'Sugiharta';
     StringGrid1.Cells[2,3] := '3';
     StringGrid1.Cells[3,3] := '3';

     StringGrid1.Cells[0,4] := '4';
     StringGrid1.Cells[1,4] := 'Kursus Delphi';
     StringGrid1.Cells[2,4] := '4';
     StringGrid1.Cells[3,4] := '4';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     TStringGridHack(StringGrid1).DeleteRow(StringGrid1.Row);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     TStringGridHack(StringGrid1).InsertRow(StringGrid1.Row);
end;


end.


Menampilkan nama font pada combobox / Tool / Windows / Delphi 7 - XE
procedure TForm1.FormCreate(Sender: TObject);
begin
     ComboBox1.Items.Assign(Screen.Fonts);
end;