You are on page 1of 12

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

MENGANALISA KODING (sebuah latihan) Mungkin rekan2 pernah melihat koding spt ini : **mztolo 071204 [18:00 wib] **sunter - jkt LOCAL oForm as Form oForm=CREATEOBJECT('mzFORM') oForm.Show(1) RETURN DEFINE CLASS mzFORM as Form autocenter=.t. height=400 width=590 Caption="mztolo 2004" ADD OBJECT command1 AS commandbutton WITH ; Top = 360, ; Left = 500, ; Height = 30, ; Width = 80, ; Caption = "Keluar" PROCEDURE init SET TALK OFF CLEAR ENDPROC PROCEDURE command1.Click Thisform.release ENDPROC ENDDEFINE *--------Jika anda cowok mari kita coba bayangkan wajah cantik Dian Sastro. Kulitnya yg halus, matanya yg indah, rambut terurai dg sehatnya dll. Jika anda cewek mari kita bayangkan sebuah form yg akan kita buat dan kita tampilkan di layar VFP tepat di tengah2 (autocenter=.t.) Form tersebut lebarnya/width 590 pixel dan tingginya/height 400 pixel Dengan judul form misalnya mztolo 2004 Di form tersebut juga akan di letakkan tombol/command button untuk menutup form. (anda tahu kan kenapa cewek lebih cepat memahami program ? karena yg dibayangkan form bukan Dian Sastro hehehehe sorry becanda)

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Coba anda copy koding di atas dan anda paste di command window VFP atau di new modul editing program yg anda buat spt ini :

Untuk menjalankan koding di atas anda cukup klik icon tanda seru ! di atas.

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Atau anda bisa paste di window command VFP spt ini :

Blok semua koding dg Ctrl + A atau kontrol A dan tekan Enter, shg akan tampil spt gambar berikut :

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Itulah form yg anda bayangkan tadi. Mari kita analisa dan coba satu persatu koding diatas. CREATEOBJECT( ) Adalah perintah untuk create/membuat sebuah object dari class object yg ada di VFP atau object aplikasi lain yg di kenal atau memungkinkan. Coba anda ketik koding berikut di window Command VFP spt ini : Test = CREATEOBJECT(form) terus ENTER Perintah ini artiya membuat sebuah object FORM dari class standard vfp yaitu form Hasil create object tersebut di letakkan di kesebuah variable bernama Test Test ini sudah bisa di sebut object form. Coba ketik berikut : Test.show(1) terus ENTER Ingat Test merupakan sebuah form, dan sebuah form memiliki property show yg berfungsi untuk menampilkan form baik scr modal (1) atau modeless (2). Dengan demikian perintah di atas berarti menampilkan form tersebut secara modal. Modal berarti user tdk akan bisa mengakses form lain sbl form ini hide atau release/close. Akan tampak di layar tampilan form spt ini :

Sekarang anda sudah tahuternyata perintah ini Test = CREATEOBJECT(form) Test.show(1) Berarti membuat form standar dan menampilkannya. Ya benar masih standar, bagaimana jika captionnya mau kita ganti. Terus lebarnya kita atur sendiri, ada tombol close di situ dll. Hal ini bisa di atasi dengan membuat definisi class form sendiri sesuai keperluan.

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Anda perhatikan koding berikut : *------DEFINE CLASS mzFORM as Form autocenter=.t. height=400 width=590 Caption="mztolo 2004" ENDDEFINE *------Arti perintah DEFINE CLASS mzFORM as Form adalah membuat definisi class form dg nama mzFORM Autocenter=.f. artinya form akan di tampilkan di tengah2. Height = 400 artinya form akan di buat dg tinggi 400 pixel. Width = 590 artinya form akan di buat dg lear 590 pixel. Caption=mztolo 2004 artinya form akan di beri judul mztolo 2004 Coba anda copy paste koding berikut dan anda jalankan di window command vfp. Ingat ya stl paste blok dulu semua baru tekan enter agar semua baris koding di jalankan. *--------Test = CREATEOBJECT(mzFORM) Test.show(1) Return DEFINE CLASS mzFORM as Form autocenter=.t. height=400 width=590 Caption="mztolo 2004" ENDDEFINE *--------Anda perhatikan yg di cetak tebal. Kenapa Test = CREATEOBJECT(mzFORM) bisa di jalankan ? bukankah createobject hanya untuk class yg di kenal saja. Betul !! Tetapi perlu anda ingat bahwa mzFORM juga merupakan sebuah class form, karena sudah di definisikan dg perintah DEFINE CLASS mzFORM as Form

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Setelah di jalankan maka akan tampil form di layar spt ini :

Perhatikan lebar, tinggi dan captionnya. Dari perintah di atas kita bisa mengambil kesimpulan bahwa untuk membuat form secara custom maka di lakukan define tersendiri. Sekarang kita coba kita tambahkan sebuah command button/tombol shg koding anda akan spt ini. *--------Test = CREATEOBJECT(mzFORM) Test.show(1) Return DEFINE CLASS mzFORM as Form autocenter=.t. height=400 width=590 Caption="mztolo 2004" ADD OBJECT command1 AS commandbutton WITH ; Top = 360, ; Left = 500, ; Height = 30, ; Width = 80, ; Caption = "Keluar" ENDDEFINE *---------

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Perintah ADD OBJECT berguna untuk menambahkan object di form atau modul pembawa/tempat/container. Karena di dlm sebuah form bisa terdapat lebih dari 1 tombol maka object tombol yg di tambahkan di berinama masing2, mis : command1 Top = 360 artinya posisi tombol dari tepi atas form sejauh 360 pixel, bingung ya ? Sama hehehe tapi coba2 aja lah nanti di ganti2 toh ini tdk terlalu penting. Left = 500 artinya dari tepi kiri form sejauh 500 pixel. Height = 30 artinya tinggi tombol 30 pixel. Width = 80 artinya lebar tombol 80 pixel. Caption=Keluar artinya tombol akan di berikan judul/ket/text Keluar yg menandakan ini merupakan tombol untuk keluar dari form. Coba anda copy dan paste di command window terus blok dan enter untuk menjalankan (bisa juga anda copy paste ke sebuah modul edting program terus anda run) sehingga hasilnya akan spt ini :

Coba anda klik tombol Keluar Apa yg terjadi ? Form tdk bisa release/close ! Kenapa ? Karena di click event tombol Keluar belum ada perintah untuk keluar. Coba anda tambahkan perintah click event berikut : PROCEDURE command1.Click Thisform.release ENDPROC Dan tambahkan koding untuk Init event form spt ini : PROCEDURE init SET TALK OFF CLEAR ENDPROC

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Sehingga koding komplitnya akan spt ini : oForm=CREATEOBJECT('mzFORM') oForm.Show(1) RETURN DEFINE CLASS mzFORM as Form autocenter=.t. height=400 width=590 Caption="mztolo 2004" ADD OBJECT command1 AS commandbutton WITH ; Top = 360, ; Left = 500, ; Height = 30, ; Width = 80, ; Caption = "Keluar" PROCEDURE init SET TALK OFF CLEAR ENDPROC PROCEDURE command1.Click Thisform.release ENDPROC ENDDEFINE Sekarang coba jalankan dan klik tombol Keluar maka form sudah bisa close/release. Anda bisa coba sendiri dg menambahkan combobox atau yg lainnya. Silahkan Dengan demikian anda diharapkan sudah bisa memahami proses pembuatan form secara koding (by coding), yg sebelumnya anda coba adalah pembuatan form secara disain (by design). Sukses untuk anda !!

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Berikut sample2 yg lain yg bisa anda pelajari :

Membuat teks yg berjalan dg timer !!


*----*!* dian s 2005 especially 4 u vfp8 LOCAL odForm as Form odForm=CREATEOBJECT('dianFORM') odForm.Show(1) RETURN DEFINE CLASS dianFORM as Form autocenter=.t. height=400 width=700 Caption="DS 2005" ADD OBJECT label1 as label WITH ; Top = 10, ; Left = 500, ; Autosize=.t.,; Caption="DIAN SATRO JALAN-JALAN SORE" ADD OBJECT Timer1 as dianTimer WITH ; Interval = 10 ADD OBJECT keluar AS commandbutton WITH ; Top = 360, ; Left = 500, ; Height = 30, ; Width = 80, ; Caption = "\<Close" PROCEDURE init =ADDPROPERTY(this,'kekiri',.t.) ENDPROC PROCEDURE keluar.Click Thisform.release ENDPROC ENDDEFINE DEFINE CLASS dianTimer as Timer OLEClass = "Timer" PROCEDURE Timer LOCAL ndian

mztolo 2005 belum ada judul hehehe

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

ndian=thisform.kekiri if ndian IF Thisform.label1.Left=1 Thisform.kekiri=.f. ELSE Thisform.label1.Left=Thisform.label1.Left-1 ENDIF ELSE IF Thisform.label1.Left=500 thisform.kekiri=.t. ELSE Thisform.label1.Left=Thisform.label1.Left+1 ENDIF endif Thisform.refresh ENDPROC ENDDEFINE *------

Yang ini sample untuk membuat form transparent !!


*----*!* dian s 2005 especially 4 u - dari solution vfp *!* thanks tuk mas hambud yg memberikanku semangat scr tdk langsung *!* tuk menampilkan sample ini *!* peringatan pemerintah : ini hanya untuk VFP8 dan minimal Win 2000 LOCAL odForm as Form odForm=CREATEOBJECT('dianFORM') odForm.Show(1) READ EVENTS DEFINE CLASS dianFORM as Form autocenter=.t. backcolor=RGB(236,233,216) height=400 width=750 Caption="Segala yg transparan selalu menggoda hati :)" showwindow=2 && As Top Level PERHATIKAN INI !! agar bisa transparan ADD OBJECT label1 as label WITH ; Top = 10, ; Left = 15, ; Autosize=.t.,; FontBold=.t.,; Fontsize=30,;

mztolo 2005 belum ada judul hehehe

10

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Forecolor=RGB(255,0,0),; Caption="HATI-HATI ADA PENAMPAKAN :)" PROCEDURE init **declarekan ini dulu DECLARE SetWindowLong In Win32Api AS _Sol_SetWindowLong Integer, Integer, Integer DECLARE SetLayeredWindowAttributes In Win32Api AS _Sol_SetLayeredWindowAttributes Integer, String, Integer, Integer _Sol_SetWindowLong(this.hWnd, -20, 0x00080000) _Sol_SetLayeredWindowAttributes(this.hWnd, 0, 255, 2) ENDPROC PROCEDURE Destroy **jo lali tuk clear DLLs yg tadi di declare CLEAR DLLS _Sol_SetWindowLong CLEAR DLLS _Sol_SetLayeredWindowAttributes ENDPROC ADD OBJECT keluar AS commandbutton WITH ; Top = 260, ; Left = 500, ; Height = 30, ; Width = 80, ; Caption = "\<Close" ADD OBJECT aksi AS commandbutton WITH ; Top = 260, ; Left = 50, ; Height = 30, ; Width = 80, ; Caption = "\<Action" ADD OBJECT spinner1 AS spinner WITH ; Increment=10,; KeyboardHighValue=255,; KeyboardLowValue=10,; SpinnerHighValue=255.0,; SpinnerLowValue=10.0,; Value=50,; Top = 220, ; Left = 50, ; Height = 30, ; Width = 60

mztolo 2005 belum ada judul hehehe

11

Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

PROCEDURE keluar.Click CLEAR EVENTS Thisform.release ENDPROC PROCEDURE aksi.Click tipisnya = this.Parent.spinner1.value _Sol_SetLayeredWindowAttributes(this.Parent.hWnd, 0, tipisnya, 2) ENDPROC ENDDEFINE *------

mztolo 2005 belum ada judul hehehe

12

You might also like