🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.database.win32
2 messages
2 total messages Started by Mark Mon, 15 Oct 2007 11:57
TSimpleDataSet: Aggregates and bits index out of range
#112
Author: Mark
Date: Mon, 15 Oct 2007 11:57
87 lines
3807 bytes
(BDS2006) I am getting a "bits index out of range" error, when applying
aggregate functions when there is a lookup field in the record. I found a
fix for this and have implemented this by making a subclass of
TSimpleDataSet. I will include the fix below. This has been working as a
charm for some time.

However, I have done some modifications on my project and now when
building/compoling my fixed "DoAggUpdates" is no longer being called.
Instead it looks like it is calling the "DoAggUpdates" of  the parent
TCustomClientDataSet.

To check things, I have done a ShowMessage of the ClassName of my dataset
component. It reports the correct name classname. If I set a breakpoint on
my OnUpdate event of my aggregate, it stops there. So DoAggUpdates is being
called. That's for sure. I have put a ShowMessage in my own DoAggUpdates.
That si not shown, so it is not going inside my method. I have "use debug
DCU's" on, have optimization off and so on, but am not able to place a
breakpoint on the DoAggUpdates of the TCustomClientDataSet. It shows as
invalid breakpoint...

I had the method as private, like it was in the parent class. I even put it
in the public section as demonstrated below. No luck. I deleted all dcu and
bpl files and rebuilt everything. No luck.

And I am 100% certain that this has worked in the past. I have absolutely no
clue, why my method is not firing... Can anyone help please ?

My fix:

type
  TSimpleDataSetFixedAggregates = class(TSimpleDataSet)
  private
    { Private declarations }
    FAggFieldsUpdated: TBits;
    FAggregates: TAggregates;
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure DoAggUpdates(IsUpdate: Boolean);
  published
    { Published declarations }
  end;

  THackedAggregate = class(TAggregate); // To have fields visible...

procedure TSimpleDataSetFixedAggregates.DoAggUpdates(IsUpdate: Boolean);
// Bugfixed version: Bits index out of range

  function Intersect(List1, List2: TBits): Boolean;
  var
    I: Integer;
    c: Integer; (** Bugfix**)
  begin
    if List1.Size > List2.Size then (** Bug fix **)
      c:= List2.Size
    else
      c:= List1.Size; (** End bug fix **)

//  for I := 0 to List1.Size - 1 do (** bug fix **)
    for I := 0 to c do  (** Bug fix **)
      if List1[I] and List2[I] then
      begin
        Result := True;
        Exit;
      end;
    Result := False;
  end;

var
  I: Integer;
  Agg: TAggregate;
begin
  ShowMessage('Why not...');
  for I := 0 to FAggregates.Count - 1 do
  begin
    Agg := FAggregates.Items[I];
    if Assigned(Agg.OnUpdate) and Agg.Active and Agg.InUse then
    begin
      if not IsUpdate or Intersect(FAggFieldsUpdated, (Agg as
THackedAggregate).DependentFields) then
        Agg.OnUpdate(Agg);
    end;
  end;
  for I := 0 to FAggFieldsUpdated.Size - 1 do
    FAggFieldsUpdated[I] := False;
end;
Re: TSimpleDataSet: Aggregates and bits index out of range
#113
Author: Mark
Date: Tue, 16 Oct 2007 13:59
109 lines
4773 bytes
Additional info:

Since the DoAggUpdates is static, I need to declare my variable as
TSimpleDataSetFixedAggregates to be sure that the correct method inside my
fixed class is called. I have declared it as such. Just to be sure, I put a
direct call to this function inside my source just to see if it would call
the correct method inside the right class. And it does. My method inside
TSimpleDataSetFixedAggregates is called when I hardcode this call.

So why isn't the right method called when it actually needs to. Instead of
my function it is calling the one of TCustomClientDataSet. Is it because the
calling function is only in TCustomClientDataSet


"Mark" <x@x> schreef in bericht news:471355d6@newsgroups.borland.com...
> (BDS2006) I am getting a "bits index out of range" error, when applying
> aggregate functions when there is a lookup field in the record. I found a
> fix for this and have implemented this by making a subclass of
> TSimpleDataSet. I will include the fix below. This has been working as a
> charm for some time.
>
> However, I have done some modifications on my project and now when
> building/compoling my fixed "DoAggUpdates" is no longer being called.
> Instead it looks like it is calling the "DoAggUpdates" of  the parent
> TCustomClientDataSet.
>
> To check things, I have done a ShowMessage of the ClassName of my dataset
> component. It reports the correct name classname. If I set a breakpoint on
> my OnUpdate event of my aggregate, it stops there. So DoAggUpdates is
being
> called. That's for sure. I have put a ShowMessage in my own DoAggUpdates.
> That si not shown, so it is not going inside my method. I have "use debug
> DCU's" on, have optimization off and so on, but am not able to place a
> breakpoint on the DoAggUpdates of the TCustomClientDataSet. It shows as
> invalid breakpoint...
>
> I had the method as private, like it was in the parent class. I even put
it
> in the public section as demonstrated below. No luck. I deleted all dcu
and
> bpl files and rebuilt everything. No luck.
>
> And I am 100% certain that this has worked in the past. I have absolutely
no
> clue, why my method is not firing... Can anyone help please ?
>
> My fix:
>
> type
>   TSimpleDataSetFixedAggregates = class(TSimpleDataSet)
>   private
>     { Private declarations }
>     FAggFieldsUpdated: TBits;
>     FAggregates: TAggregates;
>   protected
>     { Protected declarations }
>   public
>     { Public declarations }
>     procedure DoAggUpdates(IsUpdate: Boolean);
>   published
>     { Published declarations }
>   end;
>
>   THackedAggregate = class(TAggregate); // To have fields visible...
>
> procedure TSimpleDataSetFixedAggregates.DoAggUpdates(IsUpdate: Boolean);
> // Bugfixed version: Bits index out of range
>
>   function Intersect(List1, List2: TBits): Boolean;
>   var
>     I: Integer;
>     c: Integer; (** Bugfix**)
>   begin
>     if List1.Size > List2.Size then (** Bug fix **)
>       c:= List2.Size
>     else
>       c:= List1.Size; (** End bug fix **)
>
> //  for I := 0 to List1.Size - 1 do (** bug fix **)
>     for I := 0 to c do  (** Bug fix **)
>       if List1[I] and List2[I] then
>       begin
>         Result := True;
>         Exit;
>       end;
>     Result := False;
>   end;
>
> var
>   I: Integer;
>   Agg: TAggregate;
> begin
>   ShowMessage('Why not...');
>   for I := 0 to FAggregates.Count - 1 do
>   begin
>     Agg := FAggregates.Items[I];
>     if Assigned(Agg.OnUpdate) and Agg.Active and Agg.InUse then
>     begin
>       if not IsUpdate or Intersect(FAggFieldsUpdated, (Agg as
> THackedAggregate).DependentFields) then
>         Agg.OnUpdate(Agg);
>     end;
>   end;
>   for I := 0 to FAggFieldsUpdated.Size - 1 do
>     FAggFieldsUpdated[I] := False;
> end;
>
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads