Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 13 total
Thread Problem with grid and empty datasets
Tue, Nov 3 2015 3:13 PMPermanent Link

Christian Kaufmann

I have a TDataSet, bound to a TGrid. In some cases I provide an empty dataset:

{"rows":[]}

when I call LoadRows() with this string I get an error "Invalid data for dataset XXXXX".

I tried with chrome debugger but couldn't locate the error my TGrid Notifies 9 controls after Load
and somewhere in TBindableControl.Notification it fails.

Anybody else has experience with loading an empty list to a TDataSet? Should I avoid the call to
LoadRows() in this case?

cu Christian
Tue, Nov 3 2015 7:51 PMPermanent Link

Raul

Team Elevate Team Elevate

On 11/3/2015 3:13 PM, Christian Kaufmann wrote:
> I have a TDataSet, bound to a TGrid. In some cases I provide an empty dataset:
> {"rows":[]}
> when I call LoadRows() with this string I get an error "Invalid data for dataset XXXXX".

I don't normally do it this way but seems to work fine in 2.02 Build 4 -
no errors.

i tried this as a test :
   myDS.Open;
   myDS.LoadRows('{"rows":[]}');

and also if i actually load the empty dataset from server it works fine
as well

i.e.
database.loadrows(myDS);

myDS is bound to a god as well and  grid in both cases shows no data
rows as expected.

Raul
Wed, Nov 4 2015 1:28 AMPermanent Link

Christian Kaufmann

Raul wrote:

> myDS is bound to a god as well and  grid in both cases shows no data rows as expected.

Ok thanks for the feedback.

I will investigate further. It must be an exception somewhere in an event during RestoreState in
TDataSet.LoadRows. So I have to check all my bound controls again.

cu Christian
Wed, Nov 4 2015 1:46 AMPermanent Link

Christian Kaufmann

New day, fresh mind: When you bind an empty TDataset to a TGrid, the grid is not empty but shows
just one row / record. This triggers the OnGetText events for all columns.

In my case I called StrToInt(Value) for a integer column but in this case value was "" and this
caused an exception. It seems better to do it this way:


function TBSLanguage.GetTextGenderName(Sender: TObject; const Value: String): String;
var
 dc : TDataColumn;
begin
 dc := TDataColumn(Sender);
 // then use dc.AsInteger
end;

Or to check on dc.Null.


But for me remains the question, why the grid shows an empty row instead of just nothing.


cu Christian
Wed, Nov 4 2015 1:19 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< But for me remains the question, why the grid shows an empty row instead of just nothing. >>

Are you talking about run-time, or design-time ?  You shouldn't see any empty rows at run-time, but at design-time EWB puts one there so that you can see what things will look like.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Nov 4 2015 3:08 PMPermanent Link

Christian Kaufmann

Tim Young [Elevate Software] wrote:

> Are you talking about run-time, or design-time ?  You shouldn't see any empty rows at run-time,
> but at design-time EWB puts one there so that you can see what things will look like.

I have the empty row during runtime.

cu Christian
Thu, Nov 5 2015 2:15 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian

<< I have the empty row during runtime. >>

I'm not seeing that there.  Are you possibly accidentally inserting a row at some point ?  Are you putting the dataset into "Find" mode ?  Calling InitFind will add a blank row for searching.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Nov 5 2015 2:15 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


Sorry, "here", not "there".

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Nov 5 2015 3:57 PMPermanent Link

Christian Kaufmann

Tim Young [Elevate Software] wrote:

> I'm not seeing that there.  Are you possibly accidentally inserting a row at some point ?  Are
> you putting the dataset into "Find" mode ?  Calling InitFind will add a blank row for searching.
>
Yes, there is an InitFind:

function TBSDataSet.FindById(AId: Integer): Boolean;
begin
 InitFind;
 Columns['ID'].AsInteger := AId;
 Result := Find;
end;

How can I "revert" that empty row?

cu Christian
Thu, Nov 5 2015 6:53 PMPermanent Link

Raul

Team Elevate Team Elevate

On 11/5/2015 3:57 PM, Christian Kaufmann wrote:
>>
> Yes, there is an InitFind:
>
> function TBSDataSet.FindById(AId: Integer): Boolean;
> begin
>    InitFind;
>    Columns['ID'].AsInteger := AId;
>    Result := Find;
> end;
>
> How can I "revert" that empty row?

Looks like calling InitFind on empty dataset results in the blank row
becoming visible - once you call Find it gets removed again though.

It appears you might have a InitFind without matching Find if you see it
still - any chance you're calling InitFind anywhere else ?

Raul
Page 1 of 2Next Page »
Jump to Page:  1 2
Image