Saturday, September 15, 2012

Membalik Text

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

function RS(const AText: string): string;
var
  I: Integer;
  C: PChar;
begin
  SetLength(Result, Length(AText));
  C := PChar(Result);
  for I := Length(AText) downto 1 do
  begin
    C^ := AText[I];
    Inc(C);
  end;
end;

procedure TForm1.B1Click(Sender: TObject);
begin
   Form1.Caption := RS(Form1.Caption);
   B1.Caption := RS(B1.Caption);
end;

end.

Friday, June 29, 2012

Membuat Button/Tombol unik

unit Unit1;

interface

uses
   SysUtils, Graphics, Forms, StdCtrls, Classes, Controls, ExtCtrls;

type
  TForm1 = class(TForm)
    PB: TPaintBox;
    E1: TEdit;
    procedure PBPaint(Sender: TObject);
    procedure PBMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure PBMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { By : Zephio }
  public
    { http://amateur-guide.blogspot.com }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.PBPaint(Sender: TObject);
begin
with PB.Canvas do
begin
   Brush.Style := BSClear;
   Pen.Style := PSSolid;
   Font.Size := 24;
   Font.Style := [FSBold];
   Font.Name := 'Verdana';
   Font.Color := ClGray;
   TextOut(0, 0, 'Generate');
   Font.Color := CLBlue;
   TextOut(2, 2, 'Generate');
end;
end;

procedure TForm1.PBMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
with PB.Canvas do
begin
   Brush.Style := BSClear;
   Pen.Style := PSSolid;
   Font.Size := 24;
   Font.Style := [FSBold];
   Font.Name := 'Verdana';
   Font.Color := ClGray;
   TextOut(0, 0, 'Generate');
   Font.Color := CLRed;
   TextOut(2, 2, 'Generate');
end;

end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   PBPaint(Self);
end;

procedure TForm1.PBMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if Button <> MBLeft then
   Exit
else
with PB.Canvas do
begin
   Brush.Style := BSClear;
   Pen.Style := PSSolid;
   Font.Size := 24;
   Font.Style := [FSBold];
   Font.Name := 'Verdana';
   Font.Color := ClGray;
   TextOut(0, 0, 'Generate');
   Font.Color := ClLIme;
   TextOut(2, 2, 'Generate');
end;
   E1.Text := IntToHex(Random(999999), 8);
   E1.Font.Color := Random(99999);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   DoubleBuffered := true;
   Randomize;
end;

end.