Skip navigation

Dalam pembuatan program di Delphi, banyak cara dan style orang mengcoding dan me-manage “project”, salah satunya saya. Dan saya juga punya style sendiri untuk coding dan me-manage “project” dari aplikasi yang saya buat ini. Salah satu style yang pasti saya bikin di dalam pembuatan aplikasi adalah pembuatan Form Dasar (Base Form) untuk di inheritance, inheritance ini di perlukan karena ada behavior standard dari form yang memang saya pasti perlukan, diantaranya adalah sbb:

  • punya variable Last Key (inget jaman bahoela di clipper)
  • punya standard Navigasi keys untuk perpindahan tombol menggunakan tombol [enter], [key-up], [key-down]. Standard Navigasi keys ini-pun harus ber-behave benar terhadap control {ComboBox}, {ListBox}, {DateEdit}, dan {DBGrid}.
  • [ESC] adalah tombol standard untuk keluar dari Forms.
  • dan so-pasti jika Forms di CLOSE, otomatis harus langsung di FREE, heh.. biar ndak coding lagi “action := caFree”…., bosen.

penamaan untuk form saya buat dengan style saya yaitu:

  • Base Form ex: Nama File “wfBase”, Nama Object “TfBase” Var “fBase”
  • Apps Form ex: Nama File “afCust”, Nama Object “TfCust” Var “fCust”

di bawah ini adalah minimal code yang saya butuhkan, tapi bila ada penambahan Control selain dari bawaan Delphi, ya… harus di cari padanan “Base Class” ex: ComboBox-nya dari Developer Express atau Raize atau LMD agar behaviornya bisa berjalan dengan semestinya (ex: jika combo sudah drop down harus fasilitas panah atas dan bawah mati).

demikian semoga membantu….

nb. untuk form inheritance harap melihat ke help Delphi ya…. 🙂

unit wfBase;

interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids; type TfBase = class(TForm) procedure FormClose( Sender: TObject; var Action: TCloseAction); procedure FBKeyDown( Sender: TObject; var Key: Word; Shift: TShiftState); Procedure FBKeyPress(Sender: TObject; var Key: Char); protected procedure WndProc(var Message: TMessage); override; procedure DoClose(var Action: TCloseAction); override; { Private declarations } public LastKey: Integer; KeyMsg: TMessage; { Public declarations } end; var fBase: TfBase; implementation {$R *.dfm} //------------------------------------------------------------------------------ procedure TfBase.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:= caFree; end; //------------------------------------------------------------------------------ procedure TfBase.FBKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Var sClass: string; begin if not (Shift = []) then exit; if Screen.ActiveControl = Nil then Exit; sClass := Screen.ActiveControl.ClassName; if Screen.ActiveControl is TCustomCombo then begin if TCustomCombo(Screen.ActiveControl).DroppedDown then Exit; end; if Screen.ActiveControl is TDBLookupComboBox then begin if TDBLookupComboBox(Screen.ActiveControl).ListVisible then Exit; end; if Screen.ActiveControl is TCustomGrid then exit; //Base Class for Delphi.Grid Case Key of VK_DOWN: begin SelectNext(Screen.ActiveControl, True, True ); Key := 0; end; VK_UP: begin SelectNext(Screen.ActiveControl, False, True ); Key := 0; end; End; end; //------------------------------------------------------------------------------ procedure TfBase.FBKeyPress(Sender: TObject; var Key: Char); begin if Key=#27 then close; if Key<>#13 then exit; if Screen.ActiveControl = Nil then exit; if Screen.ActiveControl is TCustomCombo then begin if TCustomCombo(Screen.ActiveControl).DroppedDown then Exit; end; if Screen.ActiveControl is TCustomGrid then exit; //Base Class for Delphi.Grid SelectNext(Screen.ActiveControl, True, True ); Key:= #0; end; //------------------------------------------------------------------------------ procedure Tfbase.WndProc(var Message: TMessage); begin if Message.Msg=45102 then begin LastKey:= Message.WParam; KeyMsg := Message; end; inherited; end; //------------------------------------------------------------------------------ procedure TfBase.DoClose(var Action: TCloseAction); begin Action:= caFree; end; //------------------------------------------------------------------------------ end.


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: