+62 812-1171-5379 Fast Respond

Tips dan Trik Delphi

Membuat tampilan pesan singkat dan bagus / Tool / Windows / Delphi 7 - XE


function Pesanku(isi:String):word;
Begin
    Application.RestoreTopMosts;
    MessageDlg(isi, mtInformation, [mbOK], 0);
    Application.RestoreTopMosts;
end;


Buka tutup table Myquery / Database / Windows / Delphi 7 - XE


Function OpentableMy(Dataset: TMyQuery): Boolean;
begin
     if Dataset.Active = False then
     begin
          Dataset.Open;
     end;
end;

Function ClosetableMy(Dataset: TMyQuery): Boolean;
begin
     if Dataset.Active = True then
     begin
          Dataset.Close;
     end;
end;

Cara penghapusan data record melalui SQL / Database / Windows / Delphi 7 - XE


Function ExecQueryMy(Query: String; Dataset: TMyQuery): Boolean;
begin
     Result := False;
     Dataset.Close;
     Dataset.SQL.Clear;
     Dataset.SQL.Text := Query;
     Dataset.Execute;
     Result := True;
end;

SQL Pencarian dalam dataset / Database / Windows / Delphi 7 - XE


Function CariQueryMy(Query: String; Dataset: TMyQuery): Boolean;
begin
    Dataset.Close;
    Dataset.SQL.Clear;
    Dataset.SQL.Text := Query;
    Dataset.Open;
    if Not (Dataset.Eof or Dataset.IsEmpty) Then
    Begin
       Result:=true;
    end else
    begin
       Result:=False;
    end;
end;

Cara penggunaan

begin
    if cariquerymy('select * from t_pelanggan where kode_pelanggan=''%Andi%'' ', Myquery1) Then
    begin
        // isi statemen
    end; 
end;



Menyimpan Stringgrid menjadi file HTML / Tool / Windows / Delphi 7 - XE


procedure SGridToHtml(SG: TStringgrid; Dest: TMemo; BorderSize: Integer);
var 
  i, p: integer;
  SStyle1, SStyle2, Text: string;
begin
  Dest.Clear;
  Dest.Lines.Add('');
  Dest.Lines.Add('');
  Dest.Lines.Add('  ');

  for i := 0 to SG.RowCount - 1 do
  begin
    Dest.Lines.Add('  ');
    for p := 0 to SG.ColCount - 1 do
    begin
      SStyle1 := '';
      SStyle2 := '';
      if fsbold in SG.Font.Style then
      begin
        SStyle1 := SStyle1 + '';
        SStyle2 := SStyle2 + '';
      end;
      if fsitalic in SG.Font.Style then
      begin
        SStyle1 := SStyle1 + '';
        SStyle2 := SStyle2 + '';
      end;
      if fsunderline in SG.Font.Style then
      begin
        SStyle1 := SStyle1 + '';
        SStyle2 := SStyle2 + '';
      end;
      Text := sg.Cells[p, i];
      if Text = '' then Text := ' ';
      Dest.Lines.Add('    ');
    end;
    Dest.Lines.Add('  ');
  end;
  Dest.Lines.Add('  
' + SStyle1 + Text + SStyle2 + '
'); Dest.Lines.Add('');; Dest.Lines.Add(''); end; // Contoh penerapan procedure TFormCSVInport.Button6Click(Sender: TObject); begin SGridToHtml(StringGrid1, Memo1, 1); Memo1.Lines.SaveToFile('c:\test.html'); end;
Menguji kebenaran tanggal atau jam / Tool / Windows / Delphi 7 - XE


function IsDate(str: string): Boolean;
var
  dt: TDateTime;
begin
  Result := True;
  try
    dt := StrToDate(str);
  except
    Result := False;
  end;
end;

function IsTime(str: string): Boolean;
var
  dt: TDateTime;
begin
  Result := True;
  try
    dt := StrToTime(str);
  except
    Result := False;
  end;
end;

Menghitung jumlah kata pada kalimat / Tool / Windows / Delphi 7 - XE


function Seps(As_Arg: Char): Boolean;
begin
  Seps := As_Arg in
    [#0..#$1F, ' ', '.', ',', '?', ':', ';', '(', ')', '/', '\'];
end;

function WordCount(CText: string): Longint;
var
  Ix: Word;
  Work_Count: Longint;
begin
    Result := 0;
    Work_Count := 0;
    Ix         := 1;
    while Ix <= Length(CText) do
    begin
      while (Ix <= Length(CText)) and (Seps(CText[Ix])) do
        Inc(Ix);
      if Ix <= Length(CText) then
      begin
        Inc(Work_Count);

        while (Ix <= Length(CText)) and (not Seps(CText[Ix])) do
          Inc(Ix);
      end;
    end;
    Result := Work_Count;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     Label1.Caption := Inttostr(WordCount(Edit1.Text));
end;

Parse text / Tool / Windows / Delphi 7 - XE


function Parse(Char, S: string; Count: Integer): string;
var
  I: Integer;
  T: string;
begin
  if S[Length(S)] <> Char then
    S := S + Char;
  for I := 1 to Count do
  begin
    T := Copy(S, 0, Pos(Char, S) - 1);
    S := Copy(S, Pos(Char, S) + 1, Length(S));
  end;
  Result := T;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     Edit1.Text := (Parse('|', 'A|B|C|D|E|F', 6));
     // hasil F
end;


Menambahkan text pada sisi kanan Memo / Tool / Windows / Delphi 7 - XE


procedure TForm1.InsertText(str: string; Amemo: TMemo);
var
  Str1: string;
  i, ui: Integer;
begin
  ui   := Length(Amemo.Lines[Amemo.CaretPos.y]);
  str1 := Amemo.Lines[Amemo.CaretPos.y];
  if Pos('<$Cursor$>', str) > 0 then
  begin
    i   := Pos('<$Cursor$>', str);
    str := StringReplace(str, '<$Cursor$>', '', [rfReplaceAll, rfIgnoreCase]);
    i   := i - 1 + ui;
  end
  else
    i := -30;
  Insert(str, Str1, Amemo.CaretPos.x + 1);
  Amemo.Lines[Amemo.CaretPos.y] := str1;
  if i <> -30 then
  begin
    Amemo.SelStart := Amemo.Perform(EM_LINEINDEX, Amemo.CaretPos.y, 0) + i;
    Amemo.SetFocus;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     InsertText('kursusdelphi.com',Memo1);
end;

Menampilkan isi file pada direktory / Files / Windows / Delphi 7 - XE


procedure ListFileDir(Path: string; FileList: TStrings);
var
  SR: TSearchRec;
begin
  if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
  begin
    repeat
      if (SR.Attr <> faDirectory) then
      begin
        FileList.Add(SR.Name);
      end;
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
     ListFileDir('C:\WINDOWS\', ListBox1.Items);
end;