Tabela


Odczyt pól tabeli w "runtime"

a) właściwość FIELDS :TFields;

np. dla x:integer;

 x:=Table1.Fields[0].AsInteger; 

dla s:string;

 s:=Table1.Fields[2].AsString; 

[n] - numer pola w bieżącym rekordzie tabeli

b) metoda FieldByName(const FieldName: string):TField;

np.:

dla x:integer;

 x:=Table1.FieldByName('Wiek').AsInteger; 

c) właściwość FieldValues:Variant;

 x:=Table1.FieldValues['Wiek']; 

albo po prostu:(!!!)

x:=Table1['Wiek'];

Operowanie danymi

a) Wprowadzenie w stan edycji:
    Table1.Edit;
b) Zatwierdzanie modyfikacji:
    Table1.Post;
c) Wstawianie nowego rekordu:
    Table1.Append;
d) Usunięcie rekordu:
    Table1.delete;
e) Rezygnacja ze zmian przed ich zatwierdzeniem
    Table1.Cancel;

np.

  with Table1 do
  begin
   Append;
   FieldValues['Nazwisko']:='Kowalski;
   FieldValues['Wiek']:=21;
   Post;
  end;
f) Nawigacja:
    Table1.First; {lub FindFirst}
    Table1.Last;  {lub FindLast}
    Table1.Next;   {lub FindNext}
    Table1.Prior;  {lub FindPrior}
    Table1.MoveBy(n);
g) Sprawdzenie bieżacego położenia

Metody: .BOF , .EOF :boolean

np:

 i:=1;
 Table1.First; 
 while not Table1.EOF do 
 begin
     Table1['Lp']:=i;
     i:=i+1; 
 end; 
h) Odświeżanie:
  Table1.Refresh;
i) Bieżący stan:

właściwość:

STATE:TDataState=(dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey, dsCalcFields, dsFilter, sNewValue, dsOldValue, dsCurValue, dsBlockRead, dsInternalCalc);

j) Filtrowanie

właściwości:

FILTER:string;

FILTERED:boolean;

np.

    Table1.filter:='WIEK<18';
    Table1.Filtered:=true;
    Table1.Refresh;
j) Wyszukiwanie

Metoda .Locate

Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;

gdzie: TLocateOptions = (loCaseInsensitive, loPartialKey);

np.:

 Table1.Locate('Nazwisko','Kowalski,[]);
 Table1.Locate('Nazwisko;Wiek', VarArrayOf(['Kowal', 23]), [loPartialKey]);
Tworzenie tabeli w "runtime"
with table1 do
begin
  Close;
  TableName:='tabDBF';
  TableType:=ttDBase; {ttParadox}
  {definiowanie pól}
  {typy pól: ftString, ftFloat, ftInteger,...}
  {4-ty parametr wskazuje  czy wartość pola jest wymagana}
  with FieldDefs do
  begin
   Clear;
   Add('pole1',ftAutoInc,0,true);
   Add('pole2',ftString ,15,true);
   Add('pole3',ftString ,15,false);
   Add('pole4',ftInteger,10,false);
   Add('pole5',ftString ,10,false);
  end;
  {tworzenie indeksów}
  with IndexDefs do
  begin
   clear;
   Add('','pole1',[ixPrimary]); 
   //3-ci par.:[ixPrimary, ixUnique,  ixDescending,...]
   //dla Primary Key nazwa nie jest konieczna
   Add('pole2','pole2',[]);
   Add('pole3','pole3',[]);
   //ale można skonstruować indeks z kilku pól, np:
   Add('ind1','pole2;pole3',[]);
   //separator - ";"
  end;
  CreateTable;
  Addindex('pole4','pole4',[]);
  Open;
  IndexDefs.Update;
  IndexFieldNames:='pole2';  {albo  IndeksName:='ind1';}  
end;
{...}
Table1.Close;