Melanjutkan postingan membuat tabel pada interbase / firebird sekarang cara mengkoneksikan ke delphi nya menggunakan komponen standart Interbase. Pada contoh program kali ini ane pake Data Controls supaya minimum coding. Dan bagaimana caranya.. Langsung sajalah... :D ( newbie only )
Database : Interbase 2007
Tools : IBExpert
IDE : Delphi 7
Database : Interbase 2007
Tools : IBExpert
IDE : Delphi 7
Desain form kira-kira seperti berikut :
Double klik komponen IBDatabase1, akan muncul dialog, seting seperti pada gambar
Pada komponen IBDataset1 seting properties SelectSQL
kemudian pada komponen IBDataset1 klik kanan > Dataset Editor...
Pada komponen IBDataset1 seting properties SelectSQL
klik Get Table Fields > klik NIM pada Key Field seperti yang terlihat pada gambar
kemudian klik Generate SQL, jika benar akan menjadi seperti gambar berikut
Pada komponen ActionList1 double klik, akan muncul dialog, seting saja seperti gambar
Berikut komponen-komponen yang perlu disetting propertiesnya
Komponen | Properties | Value |
---|---|---|
Label1 | Caption | NIM |
Label2 | Caption | NAMA |
DBEdit1 | ||
DataSource | DataSource1 | |
DataField | NIM | |
DBEdit2 | ||
DataSource | DataSource1 | |
DataField | NAMA | |
IBDatabase1 | ||
DefaultTransaction | IBTransaction1 | |
Connected | True | |
IBTransaction1 | ||
Active | True | |
DefaultDatabase | IBDatabase1 | |
IBDataset1 | ||
Database | IBDatabase1 | |
Transaction | IBTransaction1 | |
DataSource1 | ||
AutoEdit | False | |
DataSet | IBDataset1 | |
DBGrid1 | ||
Align | alBottom | |
DataSource | DataSource1 | |
ReadOnly | True | |
Button1 | ||
Action | DataSetInsert1 | |
Button2 | ||
Action | DataSetPost1 | |
Button3 | ||
Action | DataSetEdit1 | |
Button4 | ||
Action | DataSetCancel1 | |
Button5 | ||
Action | DataSetDelete1 | |
ActionList1 | ||
- | - |
Hasil screenshot
Full Source Code
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, IBCustomDataSet, IBDatabase, StdCtrls, ActnList, Grids,
DBGrids, DBActns, Mask, DBCtrls;
type
TDataSetInsert = class (DBActns.TDataSetInsert)
procedure UpdateTarget(Target:TObject); override;
end;
TForm1 = class(TForm)
IBDatabase1: TIBDatabase;
IBTransaction1: TIBTransaction;
IBDataSet1: TIBDataSet;
DBGrid1: TDBGrid;
ActionList1: TActionList;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
DataSetInsert1: TDataSetInsert;
DataSetDelete1: TDataSetDelete;
DataSetEdit1: TDataSetEdit;
DataSetPost1: TDataSetPost;
DataSetCancel1: TDataSetCancel;
Button5: TButton;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TDataSetInsert }
procedure TDataSetInsert.UpdateTarget(Target: TObject);
begin
with GetDataSet(Target) do
Enabled := Active and CanModify and (State=dsBrowse);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IBDataSet1.Open;
end;
end.
Download Source Code
0 comments:
Post a Comment