Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Пример ПЗ по БД.docx
Скачиваний:
3
Добавлен:
03.03.2016
Размер:
1.79 Mб
Скачать

Приложение б. Листинг примеров (язык delphi) б1. Пример №1

Progect2.dpr:

program Project1;

uses

Forms,

Unit1 in 'Unit1.pas' {Form1},

Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin

Application.Initialize;

Application.CreateForm(TForm2, Form2);

Application.CreateForm(TForm1, Form1);

Application.Run;

end.

Unit1.pas:

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs;

type

TForm1 = class(TForm)

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

end.

Unit1.dfm

object Form1: TForm1

Left = 192

Top = 124

Width = 928

Height = 480

Caption = 'Form1'

Color = clBtnFace

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindowText

Font.Height = -11

Font.Name = 'MS Sans Serif'

Font.Style = []

OldCreateOrder = False

PixelsPerInch = 96

TextHeight = 13

End

Unit2.pas:

unit Unit2;

interface

uses

Windows, Messages, Classes, SysUtils, Graphics, Controls, StdCtrls, Forms,

Dialogs, DBCtrls, DB, DBTables, Mask, ExtCtrls;

type

TForm2 = class(TForm)

Table1EmpNo: TIntegerField;

Table1LastName: TStringField;

Table1FirstName: TStringField;

Table1PhoneExt: TStringField;

Table1HireDate: TDateTimeField;

Table1Salary: TFloatField;

ScrollBox: TScrollBox;

Label1: TLabel;

EditEmpNo: TDBEdit;

Label2: TLabel;

EditLastName: TDBEdit;

Label3: TLabel;

EditFirstName: TDBEdit;

Label4: TLabel;

EditPhoneExt: TDBEdit;

Label5: TLabel;

EditHireDate: TDBEdit;

Label6: TLabel;

EditSalary: TDBEdit;

DBNavigator: TDBNavigator;

Panel1: TPanel;

DataSource1: TDataSource;

Panel2: TPanel;

Table1: TTable;

procedure FormCreate(Sender: TObject);

private

{ private declarations }

public

{ public declarations }

end;

var

Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.FormCreate(Sender: TObject);

begin

Table1.Open;

end;

end.

Unit2.dfm

object Form2: TForm2

Left = 203

Top = 118

Width = 487

Height = 376

ActiveControl = Panel1

Caption = 'Form2'

Color = clBtnFace

ParentFont = True

OldCreateOrder = True

Position = poScreenCenter

OnCreate = FormCreate

PixelsPerInch = 96

TextHeight = 13

object Panel1: TPanel

Left = 0

Top = 0

Width = 471

Height = 33

Align = alTop

BevelOuter = bvNone

TabOrder = 0

object DBNavigator: TDBNavigator

Left = 8

Top = 4

Width = 240

Height = 25

DataSource = DataSource1

Flat = True

Ctl3D = False

ParentCtl3D = False

TabOrder = 0

end

end

object Panel2: TPanel

Left = 0

Top = 33

Width = 471

Height = 305

Align = alClient

BevelOuter = bvNone

BorderWidth = 4

Caption = 'Panel2'

TabOrder = 1

object ScrollBox: TScrollBox

Left = 4

Top = 4

Width = 463

Height = 297

HorzScrollBar.Margin = 6

HorzScrollBar.Range = 325

VertScrollBar.Margin = 6

VertScrollBar.Range = 84

Align = alClient

AutoScroll = False

BorderStyle = bsNone

TabOrder = 0

object Label1: TLabel

Left = 6

Top = 6

Width = 35

Height = 13

Caption = 'EmpNo'

FocusControl = EditEmpNo

end

object Label2: TLabel

Left = 67

Top = 6

Width = 48

Height = 13

Caption = 'LastName'

FocusControl = EditLastName

end

object Label3: TLabel

Left = 188

Top = 6

Width = 47

Height = 13

Caption = 'FirstName'

FocusControl = EditFirstName

end

object Label4: TLabel

Left = 284

Top = 6

Width = 46

Height = 13

Caption = 'PhoneExt'

FocusControl = EditPhoneExt

end

object Label5: TLabel

Left = 6

Top = 44

Width = 42

Height = 13

Caption = 'HireDate'

FocusControl = EditHireDate

end

object Label6: TLabel

Left = 132

Top = 44

Width = 29

Height = 13

Caption = 'Salary'

FocusControl = EditSalary

end

object EditEmpNo: TDBEdit

Left = 6

Top = 21

Width = 55

Height = 21

DataField = 'EmpNo'

DataSource = DataSource1

TabOrder = 0

end

object EditLastName: TDBEdit

Left = 67

Top = 21

Width = 115

Height = 21

DataField = 'LastName'

DataSource = DataSource1

TabOrder = 1

end

object EditFirstName: TDBEdit

Left = 188

Top = 21

Width = 90

Height = 21

DataField = 'FirstName'

DataSource = DataSource1

TabOrder = 2

end

object EditPhoneExt: TDBEdit

Left = 284

Top = 21

Width = 35

Height = 21

DataField = 'PhoneExt'

DataSource = DataSource1

TabOrder = 3

end

object EditHireDate: TDBEdit

Left = 6

Top = 59

Width = 120

Height = 21

DataField = 'HireDate'

DataSource = DataSource1

TabOrder = 4

end

object EditSalary: TDBEdit

Left = 132

Top = 59

Width = 65

Height = 21

DataField = 'Salary'

DataSource = DataSource1

TabOrder = 5

end

end

end

object DataSource1: TDataSource

DataSet = Table1

Left = 389

Top = 3

end

object Table1: TTable

DatabaseName = 'DBDEMOS'

TableName = 'employee.db'

Left = 361

Top = 3

object Table1EmpNo: TIntegerField

FieldName = 'EmpNo'

end

object Table1LastName: TStringField

FieldName = 'LastName'

end

object Table1FirstName: TStringField

FieldName = 'FirstName'

Size = 15

end

object Table1PhoneExt: TStringField

FieldName = 'PhoneExt'

Size = 4

end

object Table1HireDate: TDateTimeField

FieldName = 'HireDate'

end

object Table1Salary: TFloatField

FieldName = 'Salary'

end

end

end