[Lazarus] SQLite: How to create lookup fields?

Luiz Americo Pereira Camara luizmed at oi.com.br
Fri Dec 26 11:18:34 CET 2008


User escreveu:
> Hi again, my TSQLite3Dataset components:
>
> DatasetSales with the fields: Code, Item, Amount, Price, Vendor
> DatasetItems with the fields: Code, Description
>
> I do not want that the lookup field to be editable.
>
> My new code:
>
> procedure TForm1.FormCreate(Sender: TObject);
> var
>   TempField: TStringField;
> begin
>   DatasetSales.Active := true;
>   TempField := TStringField.Create(DatasetSales);
>   with TempField do
>     begin
>       FieldName := 'New field';
>       Lookup := True;
>       FieldKind := fkLookup;
>       KeyFields := 'Item';
>       LookupDataSet := DatasetItems;
>       LookupKeyFields := 'Code';
>       LookupResultField := 'Description';
>       DatasetSales := Self.DatasetSales;
>     end;
> end;
>
> but nothing happen. Why?
>   

1) There's a bug in your code:

DatasetSales := Self.DatasetSales;
should be
Dataset := DatasetSales;

and Active should be set after the field setup.

Another caution is to have DatasetItems opened before DatasetSales

 

2) It's not implemented in TSqlite3Dataset
I looked at the implementation and got  how it works, so i can implement 
in Sqlite3Dataset soon.

Luiz




More information about the Lazarus mailing list