Recent

Author Topic: [SOLVED] In DBGrid not visible result in lookup field (LookupResultField)  (Read 14349 times)

xcod

  • New Member
  • *
  • Posts: 13
I created a Firebird database with two tables
I use IBConnection of SQLdb
to form two DBGrid and DBLookupComboBox
created a lookup field in SQLQuery for DBGrid, and set the properties in DBLookupComboBox
DBGrid in the lookup value in a field is selected and modified, but not displayed
in DBLookupComboBox everything is working fine
I create a test project and attached

Please, help..where I made ​​a mistake?
Sorry for my bad english... :(
« Last Edit: May 24, 2012, 09:08:33 am by xcod »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: In DBGrid not visible result in lookup field (LookupResultField)
« Reply #1 on: May 21, 2012, 08:34:49 pm »
When you set StringField1.LookupCache to true it works.  This looks like a bug. I'll investigate further.

xcod

  • New Member
  • *
  • Posts: 13
Re: In DBGrid not visible result in lookup field (LookupResultField)
« Reply #2 on: May 22, 2012, 04:41:02 am »
Thank's for a quick reply.
I set StringField1.LookupCache to true and it's work fine. :)
Please post to bugtracker if it's bug.

Sorry for my English..

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: In DBGrid not visible result in lookup field (LookupResultField)
« Reply #3 on: May 22, 2012, 03:30:21 pm »
Quote
Please post to bugtracker if it's bug.
The problem is that TCustomBufDataset.Lookup is not implemented and TDataset.Lookup returns Null. TSQLQuery is a descendant of  TCustomBufDataset.
The issue and patch to implement TCustomBufDataset.Lookup can be found at http://bugs.freepascal.org/view.php?id=22099

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: In DBGrid not visible result in lookup field (LookupResultField)
« Reply #4 on: May 22, 2012, 04:06:17 pm »
Nice as usual. Hope it gets committed soon...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

xcod

  • New Member
  • *
  • Posts: 13
Thanks, it's fixed. :)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: [SOLVED] In DBGrid not visible result in lookup field (LookupResultField)
« Reply #6 on: December 26, 2013, 03:46:50 pm »
I'm trying to do what you have done to code, but it does not work. I enclose my source, can anyone help me solve?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

nomorelogic

  • Full Member
  • ***
  • Posts: 197
Re: [SOLVED] In DBGrid not visible result in lookup field (LookupResultField)
« Reply #7 on: December 27, 2013, 04:04:10 pm »
hi, try using this code instead of the one on your FormCreate method



Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var Temf:TStringField;
begin

          {dichiaro la struttura del dataset virtuale}
          VDSet_Chiavi.FieldDefs.Add('Id',ftInteger);
          VDSet_Chiavi.FieldDefs.Add('Chiave',ftString,50);
          VDSet_Chiavi.CreateDataset;{creo il dataset virtuale con la struttura sopra dichiarata}
          VDSet_Chiavi.Open; {apro la connessione al dataset virtuale}
          VDSet_Chiavi.Append; {dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Chiavi.Fields[0].Value:=1;
          VDSet_Chiavi.Fields[1].Value:='Carmen';
          VDSet_Chiavi.Post; {applico l'accodamento}
          VDSet_Chiavi.Append;{dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Chiavi.Fields[0].Value:=2;
          VDSet_Chiavi.Fields[1].Value:='Ti';
          VDSet_Chiavi.Post; {applico l'accodamento}
          VDSet_Chiavi.Append;{dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Chiavi.Fields[0].Value:=3;
          VDSet_Chiavi.Fields[1].Value:='Amo';
          VDSet_Chiavi.Post; {applico l'accodamento}

          {dichiaro la struttura del dataset virtuale}
          VDSet_Principale.FieldDefs.Add('Id_Chiave',ftInteger);
          VDSet_Principale.FieldDefs.Add('Utente',ftString,50);
          VDSet_Principale.FieldDefs.Add('NewLookUpField',ftString,50);
          VDSet_Principale.CreateDataset;{creo il dataset virtuale con la struttura sopra dichiarata}

          Temf := TStringField(VDSet_Principale.Fields.FindField('NewLookUpField'));

          Temf.FieldKind := fkLookup;
          Temf.LookupDataSet:=Self.VDSet_Chiavi;
          Temf.LookupCache:=FALSE;
          Temf.LookupKeyFields:='ID';
          Temf.LookupResultField:='CHIAVE';
          Temf.ReadOnly:=FALSE;
          Temf.ProviderFlags:=[pfInUpdate, pfInWhere];
          Temf.Required:=FALSE;
          Temf.KeyFields:='Id_Chiave';

          VDSet_Principale.Open; {apro la connessione al dataset virtuale}
          VDSet_Principale.Append; {dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Principale.Fields[0].Value:=1;
          VDSet_Principale.Fields[1].Value:='root';
          VDSet_Principale.Post; {applico l'accodamento}
          VDSet_Principale.Append;{dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Principale.Fields[0].Value:=2;
          VDSet_Principale.Fields[1].Value:='root';
          VDSet_Principale.Post; {applico l'accodamento}
          VDSet_Principale.Append;{dico che voglio accodare dei dati al dataset virtuale}
          VDSet_Principale.Fields[0].Value:=3;
          VDSet_Principale.Fields[1].Value:='root';
          VDSet_Principale.Post; {applico l'accodamento}


          Self.DBGrid2.Columns[0].Width:=50;
          Self.DBGrid2.Columns[1].Width:=100;
          Self.DBGrid2.Columns[2].Width:=100;


          exit;


          VDSet_Principale.Fields[2].FieldKind:=fkLookUp;
          VDSet_Principale.Fields[2].DataSet := Self.VDSet_Principale;
          VDSet_Principale.Fields[2].LookupDataSet := Self.VDSet_Chiavi;
          VDSet_Principale.Fields[2].KeyFields := 'ID';
          VDSet_Principale.Fields[2].LookupKeyFields := 'Chiave';
          VDSet_Principale.Fields[2].LookupResultField := 'ID_Chiave';
          VDSet_Principale.Fields[2].LookupCache := true;


          Self.DBLookupComboBox1.Visible:=FALSE;
          Self.DBLookupComboBox1.LookupCache:=TRUE;
          Self.DBLookupComboBox1.DataSource:=Self.DS_Principale;
          Self.DBLookupComboBox1.DataField:='Id_Chiave';
          Self.DBLookupComboBox1.ListSource:=Self.DS_Chiavi;
          Self.DBLookupComboBox1.KeyField:='Id';
          Self.DBLookupComboBox1.ListField:='Chiave';

end;


Edit:
if you don't need a TStringField you can avoid typecast changing the declaration of Temf in:
Code: [Select]
var Temf:TField;
and, changing the line
Code: [Select]
Temf := TStringField(VDSet_Principale.Fields.FindField('NewLookUpField'));with following
Code: [Select]
Temf := VDSet_Principale.Fields.FindField('NewLookUpField');
« Last Edit: December 27, 2013, 04:11:44 pm by nomorelogic »

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: [SOLVED] In DBGrid not visible result in lookup field (LookupResultField)
« Reply #8 on: December 27, 2013, 05:33:38 pm »
Thank you very much  :D
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
They also do not understand why at the start of my program which I am attaching does not auto populate the field NewLookUpField. You know tell me why, would he do if the fields were indexed.


Is a BUG?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

nomorelogic

  • Full Member
  • ***
  • Posts: 197
Re: [SOLVED] In DBGrid not visible result in lookup field (LookupResultField)
« Reply #10 on: January 02, 2014, 04:34:37 pm »
I think an Index cannot be the solution.
Running as downloaded from previous message, the 3rd column is empty for all records (-> lookup field seems it is not a "lookup field").

You can replace the block of code after comment " //INSERISCO UN PO' DI DATI NEL DATASET VIRTUALE PRINCIPALE"
with following block.
After replace, you can run and this is what we can expect at startup from a lookup field.
Surely this is not the solution.


Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var
  Temf:TField;
  CurrKey: integer;
begin
...

     //INSERISCO UN PO' DI DATI NEL DATASET VIRTUALE PRINCIPALE
     VDSet_Principale.Open; {apro la connessione al dataset virtuale}

     CurrKey := 1;
     VDSet_Principale.AppendRecord([CurrKey,'root', VDSet_Chiavi.Lookup('ID', CurrKey, 'Chiave') ]);

     CurrKey := 2;
     VDSet_Principale.AppendRecord([2,'toor', VDSet_Chiavi.Lookup('ID', CurrKey, 'Chiave') ]);

     CurrKey := 3;
     VDSet_Principale.AppendRecord([3,'pippo', VDSet_Chiavi.Lookup('ID', CurrKey, 'Chiave')]);
...

 

TinyPortal © 2005-2018