Page 1 of 1

TUniQuery not seen as a TDataSet;

Posted: Wed 22 Apr 2015 19:25
by SteveInIT
I have a form I am trying to pass referenced objects to for processing column widths on a FormShow event. Basically, I iterate through the form with .components, and when it finds them, it grabs the DBGrid, tries to access the dataset name of the TUniQuery that is tied to the DBGrid, and then passes them off to another unit where the procedure cycles through the dbgrid and sets the column widths.

I understand that I had to cast the "TheGrid" variable as a TDBGrid for it to work. The problem I'm having is that when accessing what dataset is used for TheGrid, it errors with

"E2010 Incompatible types:'TUniQuery' and 'TDataSet'"

I need to apologize in advance. I haven't done any coding in 15 years and I'm in a rush here to get this done.

I'm using Delphi XE7 and UniDac 6.1.3

Here is the code-

Code: Select all

procedure TDistricts.FormShow(Sender: TObject);
var
  i: integer;
  UQObject: TUniQuery;
  TheGrid: TDBGrid;
  TheWindow: TForm;

begin
  TheWindow := Districts;
  for i := 0 to Districts.ComponentCount - 1 do
  begin
    if Districts.Components[i] is TDBGrid then
      begin
        TheGrid := (Districts.Components[i])as TDBGrid;
        UQObject := TheGrid.DataSource.DataSet;

Re: TUniQuery not seen as a TDataSet;

Posted: Wed 22 Apr 2015 19:33
by FredS
SteveInIT wrote:I haven't done any coding in 15 years and I'm in a rush here to get this done.
I know exactly how that feels :)

Just typecast it:

Code: Select all

UQObject := TUniQuery(TheGrid.DataSource.DataSet);

Re: TUniQuery not seen as a TDataSet;

Posted: Thu 23 Apr 2015 09:59
by azyk
The solution suggested by FredS is correct. You can also use an additional check before this assignment:

Code: Select all

if TheGrid.DataSource.DataSet is TUniQuery then
  UQObject := TUniQuery(TheGrid.DataSource.DataSet);

Re: TUniQuery not seen as a TDataSet;

Posted: Thu 23 Apr 2015 18:15
by SteveInIT
:D It's all working now...thanks for your time Fred and Azyk!

Re: TUniQuery not seen as a TDataSet;

Posted: Fri 24 Apr 2015 11:58
by azyk
If any other questions come up, please contact us.

Re: TUniQuery not seen as a TDataSet;

Posted: Fri 24 Apr 2015 14:35
by SteveInIT
Will do! Thanks!