November 19, 2006 by kifmesoft
Setelah mendapatkan sedikit gambaran tentang String dan Komentar yang saling mematikan, maka kita dapat membuat fungsi (Function) yang dapat kita gunakan untuk membuang komentar source code Delphi. Ehmmm.. mengapa ya komentar harus dibuang ?? .. yaa.. mungkin karena ingin disembunyikan, atau mungkin karena komentarnya nggak mutu, atau .. yaaaa.. seperti yang di iklan obsesi artis itu.. no comment .. hehe.. apa aja dech..
Berikut ini saya kutipkan lagi tentang tanda komentar yang terdapat pada Delphi Help :
Comments are ignored by the compiler, except when they function as separators (delimiting adjacent tokens) or compiler directives.
There are several ways to construct comments:
{ Text between a left brace and a right brace constitutes a comment. }
(* Text between a left-parenthesis-plus-asterisk and an asterisk-plus-right-parenthesis also constitutes a comment. *)
// Any text between a double-slash and the end of the line constitutes a comment.
A comment that contains a dollar sign ($) immediately after the opening { or (* is a compiler directive. For example,
{$WARNINGS OFF}
tells the compiler not to generate warning messages.
Pada kutipan tersebut.., intinya adalah.., tanda komentar yang digunakan pada source code Delphi terdiri dari tanda blok komentar dan baris komentar, kemudian jika tepat sesudah tanda blok komentar pembuka terdapat tanda $ maka blok komentar tersebut harus dianggap sebagai compiler directive. Dan berikut ini adalah fungsi untuk membuang komentar source code Delphi
Function kifStripComment(const S: String): String;
Type
TTipeTanda = (ttDirective1, ttDirective2, ttBlockComment1,
ttBlockComment2, ttLineComment, ttString);
Const
eol = #13#10;
tanda_awal: Array [TTipeTanda] Of String =
('{$', '(*$', '{', '(*', '//', '''');
tanda_akhir: Array [TTipeTanda] Of String =
('}', '*)', '}', '*)', eol, '''');
Var
i: TTipeTanda;
ps, pe, pl, pr, po: PChar;
Begin
Result:= '';
SetLength(Result, Length(S));
pr:= PChar(Result); ps:= PChar(S); pl:= ps;
pe:= Pointer(Integer(ps) + Length(S));
While ps < pe Do
Begin
For i:= ttDirective1 To ttString Do
If (Integer(pe) - Integer(ps)) >=
Length(tanda_awal[i]) Then
If AnsiStrLComp(ps, PChar(tanda_awal[i]),
Length(tanda_awal[i])) = 0 Then
Begin
If (i In [ttBlockComment1, ttBlockComment2,
ttLineComment]) And (ps > pl) Then
Begin
StrMove(pr, pl, Integer(ps) - Integer(pl));
pr:= Pointer(Integer(pr) +
(Integer(ps) - Integer(pl)));
End;
ps:= Pointer(Integer(ps) + Length(tanda_awal[i]));
po:= AnsiStrPos(ps, PChar(tanda_akhir[i]));
If po <> Nil Then
Begin
ps:= Pointer(Integer(po) +
Length(tanda_akhir[i]));
If i = ttLineComment Then pl:= po;
End;
If i In [ttBlockComment1, ttBlockComment2] Then
pl:= ps;
ps:= Pointer(Integer(ps) - 1);
Break;
End;
ps:= Pointer(Integer(ps) + 1);
End;
If pl < pe Then
Begin
StrMove(pr, pl, Integer(pe) - Integer(pl));
pr:= Pointer(Integer(pr) + (Integer(pe) - Integer(pl)));
End;
SetLength(Result, Integer(pr) - Integer(PChar(Result)));
End;
|
|
Berikut ini adalah gambar contoh penggunaan kifStripComment :

Download Source Code
Posted in Delphi | 4 Comments »
November 18, 2006 by kifmesoft
Komentar atau Comment pada Source Code program Delphi adalah bagian yang diabaikan (tidak diproses) oleh Compiler / Interpreter. Komentar selalu memiliki tanda awal dan tanda akhir, dan berikut ini adalah kutipan mengenai komentar yang ada pada Delphi Help :
Comments are ignored by the compiler, except when they function as separators (delimiting adjacent tokens) or compiler directives.
There are several ways to construct comments:
{ Text between a left brace and a right brace constitutes a comment. }
(* Text between a left-parenthesis-plus-asterisk and an asterisk-plus-right-parenthesis also constitutes a comment. *)
// Any text between a double-slash and the end of the line constitutes a comment.
A comment that contains a dollar sign ($) immediately after the opening { or (* is a compiler directive. For example,
{$WARNINGS OFF}
tells the compiler not to generate warning messages.
Bagian lain dari source code delphi yang akan mematikan fungsi komentar (membuatnya menjadi bukan komentar) adalah String (runtun karakter yang diawali dan diakhiri oleh tanda kutip tunggal). Berbeda dengan tanda komentar (memiliki tanda yang berpasangan), maka string tidak memiliki tanda yang berpasangan (tanda awal dan tanda akhir string adalah sama, yaitu kutip tunggal).
Read the rest of this entry »
Posted in Delphi | 2 Comments »
October 8, 2006 by kifmesoft
Bila kita ingin menyembunyikan data pada suatu file maka kita bisa melakukannya dengan proses Enkripsi / Penyandian terhadap file tersebut, sehingga data pada file tersebut tidak dapat diakses lagi kecuali oleh pemiliknya. Apakah cukup seperti itu saja … ?, jawabnya bisa ya, bisa juga tidak.
ehhmm.. file hasil Enkripsi tentunya menjadi acak (tidak bisa dibuka), dan ini akan menimbulkan rasa penasaran bagi orang lain yang tidak awam, terlebih lagi bila file tersebut adalah file hasil proses kompresi (misalnya dengan WinZip atau WinRAR). Jika suatu saat ada yang bertanya : “Ini file apa ? … apa sih isinya ??”, nah, bagaimana kita akan menjawabnya ? terlebih lagi jika yang bertanya adalah teman dekat kita …
(atau misalnya pacar anda sendiri) .. hehe
Read the rest of this entry »
Posted in Delphi | 8 Comments »
October 6, 2006 by kifmesoft
Bila suatu saat kita ingin mempublikasikan source code Object Pascal ke Blog / Weblog maka kita perlu terlebih dahulu mengubahnya (export) ke format HTML. Untuk keperluan tersebut, kita dapat memanfaatkan http://delphi-id.org/syntax yang selalu setia melayani anda..
tetapi .. jika kita tidak siap untuk dilayani karena sesuatu hal.. (ya misalnya saja karena kita sedang tidak punya koneksi ke internet) nah, sebagai alternatifnya .. untuk proses export ke HTML kita dapat memanfaatkan komponen SynEdit (Exporter HTML)
Read the rest of this entry »
Posted in Delphi | Leave a Comment »