Riporto l'intera funzione che permette alla pressione di un click di generare una IBTable e con due campi e due indici.
Vorrei concentrare la vostra attenzione sula riga di codice evidenziata in nero che contiene la parola chiave "with".
Come tutti ben sappiamo la parola chiave "with" permette di costruire un blocco in cui è possibile accedere all'oggetto
preceduto da questa parola chiave, senza citare il nome dell'oggetto + l'operatore di referenza, ma solamente specificando gli attributi dell'oggetto all'interno del blocco creato da "with".
In questo caso "with" non è seguito dal nome di un oggetto, ma bensì dal nome di una procedura.
Inoltre "with" punta indirettamente ad un oggetto TFieldDef, come è possibile?
Per favore autatemi, ho un enorme dubbio.
Grazie.
->
procedure TForm1.Button1Click(Sender: TObject);
begin
with IBTable1 do begin
Active := False;
{ First, give the table a database }
Database := IBDataBase1;
TableName := 'CustInfo';
{ Next, describe the fields in the table }
with FieldDefs do begin
Clear;
with AddFieldDef do begin
Name := 'Field1';
DataType := ftInteger;
Required := True;
end;
with AddFieldDef do begin
Name := 'Field2';
DataType := ftString;
Size := 30;
end;
end;
{ Next, describe any indexes }
with IndexDefs do begin
Clear;
with AddIndexDef do begin
Name := '';
Fields := 'Field1';
Options := [ixPrimary];
end;
with AddIndexDef do begin
Name := 'Fld2Indx';
Fields := 'Field2';
end;
end;
{ Call the CreateTable method to create the table }
CreateTable;
end;
end;
end.
<-