home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / insquery.pak / INSFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-08-24  |  1.6 KB  |  77 lines

  1. unit Insform;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, DB, DBTables;
  8.  
  9. type
  10.   TInsertForm = class(TForm)
  11.     NameEdit: TEdit;
  12.     CapitalEdit: TEdit;
  13.     ContinentEdit: TEdit;
  14.     AreaEdit: TEdit;
  15.     PopulationEdit: TEdit;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     Label4: TLabel;
  20.     Label5: TLabel;
  21.     InsertBtn: TButton;
  22.     CancelBtn: TButton;
  23.     InsertQuery: TQuery;
  24.     procedure InsertBtnClick(Sender: TObject);
  25.     procedure FormCreate(Sender: TObject);
  26.   public
  27.     procedure Clear;
  28.   end;
  29.  
  30. var
  31.   InsertForm: TInsertForm;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. procedure TInsertForm.Clear;
  38. begin
  39.   ActiveControl := NameEdit;
  40.   NameEdit.Clear;
  41.   CapitalEdit.Clear;
  42.   ContinentEdit.Clear;
  43.   AreaEdit.Clear;
  44.   PopulationEdit.Clear;
  45. end;
  46.  
  47. procedure TInsertForm.InsertBtnClick(Sender: TObject);
  48. begin
  49.   InsertQuery.Close;
  50.   InsertQuery.Params[0].AsString := NameEdit.Text;
  51.   InsertQuery.Params[1].AsString := CapitalEdit.Text;
  52.   InsertQuery.Params[2].AsString := ContinentEdit.Text;
  53.   try
  54.     InsertQuery.Params[3].AsFloat := StrToFloat(AreaEdit.Text);
  55.   except
  56.     AreaEdit.SelectAll;
  57.     AreaEdit.SetFocus;
  58.     raise;
  59.   end;
  60.   try
  61.     InsertQuery.Params[4].AsFloat := StrToFloat(PopulationEdit.Text);
  62.   except
  63.     PopulationEdit.SelectAll;
  64.     PopulationEdit.SetFocus;
  65.     raise;
  66.   end;
  67.   InsertQuery.ExecSQL;
  68.   ModalResult := mrOK;
  69. end;
  70.  
  71. procedure TInsertForm.FormCreate(Sender: TObject);
  72. begin
  73.   InsertQuery.Prepare;
  74. end;
  75.  
  76. end.
  77.