Recent

Author Topic: Component and required packages  (Read 205 times)

iXaw

  • New member
  • *
  • Posts: 8
Component and required packages
« on: March 15, 2019, 09:22:53 am »
Hello,
I override a  TcustomDbGrid.

Code: Pascal  [Select]
  1. TlzDbGrid = class(TCustomDBGrid)

I use codes where a generic Dataset would be very useful :
Code: Pascal  [Select]
  1. [...] (DataSource.DataSet as TUniQuery).IndexFieldNames [...];
or
Code: Pascal  [Select]
  1. [...] (DataSource.DataSet as TZQuery).IndexFieldNames [...];

My problem is that on some of my PCs, ZeosLib is installed, on other Unidac, on some of them only TSQLQuery is present.

The ideal would be to create a generic TxxSQLQuery. I have no idea of ​​the approach needed especially since referring to Unidac or ZeosLib if they are not installed makes little sense.

So I wonder more prosaically if it is possible to detect Unidac or ZeosLib in the lpk of my component.
I have some elements but I can not connect them functionally :
  • <Packagefile.xml> <Name value ="dclunidac10"/>
  • Primary  and secondaryConfigPath
  • <CustomOptions Value="if... ????.... -dUSEUNICODE"/>
  • {$IFDEF USEUNICODE}
    [...] (DataSource.DataSet as TUniQuery).IndexFieldNames [...];
    {$ENDIF}

Can anyone suggest me a functional idea ?
Thanks. Regards. Gilles
« Last Edit: March 15, 2019, 09:35:07 am by iXaw »

wadman

  • New member
  • *
  • Posts: 35
    • wadman's home
Re: Component and required packages
« Reply #1 on: March 15, 2019, 09:34:40 am »
Code: Pascal  [Select]
  1. (DataSource.DataSet as TSQLQuery).IndexFieldNames;
Maybe they have one ancestor?


iXaw

  • New member
  • *
  • Posts: 8
Re: Component and required packages
« Reply #2 on: March 15, 2019, 09:55:19 am »
Thank you for your reply.

So with installed Unidac :
Code: Pascal  [Select]
  1. procedure TlzDbGrid.edSEARCHChange(Sender: TObject);
  2. {uses uni}
  3. begin
  4.     with TuniQuery(DataSource.DataSet) do
  5.     if String(edSEARCH.Text).IsEmpty then
  6.     First
  7.     else
  8.     Locate(IndexFieldNames,edSEARCH.Text,[loCaseInsensitive ,loPartialKey]);
  9. end;
This code works fine.

I add : uses sqldb in lzDbGrid.pas
and modify its code :
Code: Pascal  [Select]
  1. procedure TlzDbGrid.edSEARCHChange(Sender: TObject);
  2. {uses sqldb}
  3. begin
  4.     with TSQLQuery(DataSource.DataSet) do
  5.     if String(edSEARCH.Text).IsEmpty then
  6.     First
  7.     else
  8.     Locate(IndexFieldNames,edSEARCH.Text,[loCaseInsensitive ,loPartialKey]);
  9. end;
No error compile but "obviously" the code no longer works.

In https://www.freepascal.org/docs-html/fcl/db/tdataset.html,
I did not see anything that could solve my problem quite simply.
« Last Edit: March 15, 2019, 09:59:45 am by iXaw »

wadman

  • New member
  • *
  • Posts: 35
    • wadman's home
Re: Component and required packages
« Reply #3 on: March 15, 2019, 10:10:26 am »
unfortunately hierarchy looks like

TMemDataSet
   TCustomDADataSet
      TCustomUniDataSet
         TUniQuery


It remains to add a grid property with a list of fields.


Or use typinfo:
Code: Pascal  [Select]
  1.  
  2. procedure TForm1.FormCreate(Sender: TObject);
  3. begin
  4.     Caption := GetStrProp(Button1, 'Caption');
  5. end;
  6.  
« Last Edit: March 15, 2019, 10:40:46 am by wadman »

iXaw

  • New member
  • *
  • Posts: 8
Re: Component and required packages
« Reply #4 on: March 15, 2019, 12:29:29 pm »
I guess you're referring to this kind of approach

https://stackoverflow.com/questions/54953288/discover-data-aware-controls-linked-to-a-dataset-field.
In my opinion this is anachronistic.

Before defining my class, I specify my uses. It is therefore at the time of installation of the component that it is played.

I need to detect it (in the lpk file) and create the variable -dUSEUNIDAC to generate the proper compilation. So if Unidac is a package installed (packagefile.xml), the uses of my
will look like this :
Code: Pascal  [Select]
  1. {£IFDEF USEUNIDAC}
  2. uni,
  3. {$ENDIF}
Regards. Gilles


« Last Edit: March 15, 2019, 12:31:13 pm by iXaw »