Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
-
SteveInIT
- Posts: 9
- Joined: Wed 22 Apr 2015 17:42
Post
by SteveInIT » Wed 22 Apr 2015 19:25
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;
-
FredS
- Posts: 272
- Joined: Mon 10 Nov 2014 17:52
Post
by FredS » Wed 22 Apr 2015 19:33
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);
-
azyk
- Devart Team
- Posts: 1119
- Joined: Fri 11 Apr 2014 11:47
- Location: Alpha Centauri A
Post
by azyk » Thu 23 Apr 2015 09:59
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);
-
SteveInIT
- Posts: 9
- Joined: Wed 22 Apr 2015 17:42
Post
by SteveInIT » Thu 23 Apr 2015 18:15

It's all working now...thanks for your time Fred and Azyk!
-
azyk
- Devart Team
- Posts: 1119
- Joined: Fri 11 Apr 2014 11:47
- Location: Alpha Centauri A
Post
by azyk » Fri 24 Apr 2015 11:58
If any other questions come up, please contact us.