Jump to content
Squall_FF8

Aggregates for TFDQuerry

Recommended Posts

Hey guys,
I wanted to do simple thing - use Aggregates. So following the help:

procedure TForm.Button1Click(Sender: TObject);
begin
  if Qry.Aggregates.Count = 0 then
    with Qry.Aggregates.Add do begin
      Expression := 'COUNT(Town)';
      Active := True;
      Qry.AggregatesActive := true;
    end;
end;

Should be pretty simple, right? But I get error (on  Activate := true):
image.thumb.png.30d3359ae0abb651fefc385e09e43f2d.png Do you know why? What I'm doing wrong?

Share this post


Link to post

First of all do not use with it is always a bad idea.

 

You are not setting the name property for the aggregate object.

 

Edit. I have checked even the examples on docwiki are wrong. 

Edited by Lajos Juhász
  • Thanks 1

Share this post


Link to post
47 minutes ago, Lajos Juhász said:

You are not setting the name property for the aggregate object.

Thank you very much!!! Usually thigs like this have default name that is good enough (it works, the name = you dont use/dont care)

 

50 minutes ago, Lajos Juhász said:

First of all do not use with it is always a bad idea.

Are you talking for Aggregates in general, or my example of use?

Share this post


Link to post
54 minutes ago, Squall_FF8 said:

Are you talking for Aggregates in general, or my example of use?

 

in general, when using with you can never sure to which object you are assigning a value. It can work in one version of Delphi and break in the next one. You can always write:

 

var
  a: TFDAggregate;
begin
  if Qry.Aggregates.Count = 0 then
  begin
     a:=Qry.Aggregates.Add;
     a.Expression := 'COUNT(Town)';
     a.Active := True;
     a.Name:='NoName';
     Qry.AggregatesActive := true;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×