.
TDataSet , :
procedure First;
procedure Last;
procedure Next;
procedure Prior;
property BOF: Boolean read FBOF;
property EOF: Boolean read FEOF;
procedure MoveBy(Distance: Integer);
:
Table1.First .
Table1.Last .
Table1.Next .
Table1.Prior .
BOF EOF, , .
MoveBy N . Table1.Next Table1.MoveBy(1). , Table1.Prior , Table1.MoveBy(-1).
, TTable, TDataSource TDBGrid . DBGrid1 DataSource1 DataSource1 Table1. :
1. DatabaseName ( , Example);
2. TableName Example.
, TDBGrid, , (scrollbar) DBGrid.
, , . .
, . 1.3.
. 1.3.
- :
procedure TForm1.NextClick(Sender: TObject);
begin
end;
, :
procedure TForm1.NextClick(Sender: TObject);
begin
Table1.Next;
end;
, :
procedure TForm1.PriorClick(Sender: TObject);
begin
Table1.Prior;
end;
. , .
, . 1.4.
.
procedure TForm1.FirstClick(Sender: TObject);
begin
Table1.First;
end;
. 1.4.
procedure TForm1.LastClick(Sender: TObject);
|
|
begin
Table1.Last;
end;
. First , Last , Next Prior .
TDataSet.BOF - read-only Boolean , , . BOF true :
1. , ;
2. , TDataSet.First;
3. , TDataSet.Prior .
- . , Delphi ; First, Delphi . , , : , Prior , , Prior - BOF True.
Prior, :
while not Table.Bof do
begin
//
Table1.Prior;
end;
, , ( ). , Table1.Prior . BOF True . ( , DataSource1.Enabled False True .)
BOF EOF. , , , dataset:
Table1.First;
while not Table.Eof do
begin
//
Table1.Next;
end;
, : while repeat, Table1.Next:
Table1.First;
repeat
//
until Table1.EOF;
, , , Ctrl-Alt-Del . , , . repeat, , . , while repeat .
EOF True :
1. , ;
2. , TDataSet.Last;
3. , TDataSet.Next .
, - MoveBy, N . , :
MoveBy(2);
, :
MoveBy(-2);
, DataSet - , , , .
Prior Next - , MoveBy.
|
|
, , , TDataSet:
property Fields[Index: Integer];
function FieldByName(const FieldName: string): TField;
property FieldCount;
FieldCount . , Fields :
var
S: String;
begin
S:= Fields[0].FieldName;
end;
Sht_faktura, , Sht_faktura S. , :
S:= Fields[1].FieldName;
, , Fields ( ), , , .. - , - .
, Fields FieldsByName. , , Fields:
S:= Fields[3].AsString;
, FieldsByName Fields:
S:= FieldsByName(Pokupatel).AsString;
, FieldsByName, Fields . , DataSet.
. , DataSource, TTable, ListBox - Fields Values (. . 1.5).
Double click , :
procedure TForm1.FieldsClick(Sender: TObject);
var
i: Integer;
begin
ListBox1.Clear;
for i:= 0 to Table1.FieldCount - 1 do
ListBox1.Items.Add(Table1.Fields[i].FieldName);
end;
. 1.5. , Fields
ListBox1, , ListBox1. , , 0 FieldCount - 1. FieldCount, List Index Out of Bounds, , .
Delphi , , Run Time.
Fields , . :
procedure TForm1.ValuesClick(Sender: TObject);
var
i: Integer;
begin
ListBox2.Clear;
for i:= 0 to Table1.FieldCount - 1 do
ListBox2.Items.Add(Table1.Fields[i].AsString);
end;
listbox. , FieldCount - 1.
Fields , Fields[N].AsString. , . , TField:
property AsBoolean
property AsFloat
property AsInteger
property AsString
property AsDateTime
( ) Delphi . , Delphi Boolean Integer Float, Integer String. String Integer, Float Integer. Date DateTime, AsString AsFloat .
|
|
, FieldByName , :
S:= Table1.FieldByName(Pokupatel).AsString;
, , . , , , , , , .
, , . , , -. . Table1. (. 1.6,). Add fields... ( ). , . 1.6,, . . Ctrl, . , , , . . , , , (. 1.6, ).
. , - .
- . , - , : TStringField, TSmallintField, TBooIeanFicld .. TField . , . , .
) )
)
. 1.6. : (), (), ().
Alignment : , .
DisplayLabel . , Sht_faktura DisplayLabel -, Pokupatel ..
DisplayWidth .
. 1.7.
EditMask EditFormat .
ReadOnly, true, . Visible , .
(. 1.7).
, TTable:
procedure Append;
procedure Insert;
procedure Cancel;
procedure Delete;
procedure Edit;
procedure Post;
- TDataSet, TTable TQuery.
, , DataSet . , , , . TTable , .
|
|
, :
Table1.Edit;
Table1.FieldByName(Pokupatel).AsString:= ;
Table1.Post;
. Pokupatel. , , Post.
. . , , , , :
Table1.Edit;
Table1.FieldByName(Pokupatel).AsString:= ;
Table1.Next;
, , - , , . , First, Next, Prior Last Post, .
, Post. , , Cancel.
, Append Insert, , DataSet. Append DataSets, , Delphi exception, Append . , Append, Insert.
. , TTable, TDataSource TdbGrid. . . , , .1.8.
.
:
procedure TForm1.InsertClick(Sender: TObject);
begin
Table1.Insert;
Table1.FieldByName(Sht_faktura).AsString:= '6';
Table1.FieldByName(Prodavec).AsString:= ' ';
Table1.FieldByName(Pokupatel).AsString:= ' ';
Table1.FieldByName(edinica).AsString:= .';
Table1.FieldByName(kolvo).AsString:= 2';
Table1.FieldByName(Price).AsString:= 265000';
Table1.Post;
end;
.1.8.
:
procedure TForm1.DeleteClick(Sender: TObject);
begin
Table1.Delete;
end;
, , ( dataset). . , , . DBGrid. (TEdit) , :
Table1.FieldByName(Name).AsString:= Edit1.Text;
, DataSet.
, , , , . , , Post.
Insert , Cancel. , Post, Insert , dataset , Insert.
, , CanModify. CanModify False, TTable ReadOnly. CanModify True, . CanModify - read only . DataSet (Read Only), ReadOnly, CanModify.
|
|
, , , , .
, , , , , | ||
, , , , , | ||
, , , , , | ||
, , , , , |