Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread TQuery Dynamically create & free fields only works 1st time
Thu, Apr 1 2010 7:54 PMPermanent Link

Neil Huhta

Hello All:

   I have created a report writer based on a TDBISAMQuery component.
However, to keep things thin, I am dynamically creating most of the query at
runtime.

   I am running DBISAM 1 - but the structure is all TDataset descendant so
it sould be the same with all versions.

   I have a query component with the calcfields statically defined so that
those fields can be compiled in my code. Then, I am adding the fields the
user is selecting using procedures like MakeFloatfield below.

   I need the fields created so I can hook into Reportbuilder and build a
report dynamically. Even if I don't - I dont want to change my architecture.

   The first time the report runs - it is successful.

   The second time the report runs, it executes code to clean up the
previously created fields in proc CLEARTEMPQUERYFIELDDEFS - then it
recreates the fields.

   But - the report always fails the 2nd time. It throws an exception
saying QryBHRpt: Field 'BMiddle' Not Found. BMiddle is the only field added
from the first to the second time in the report.

  Anybody know what I am doing wrong here ??? The file has lots of fields -
so I am trying to keep the query small.

Thank you.

Neil Huhta




procedure TfmBHDealReports.MakeFloatField(NewFieldName, FAction:
String;FSize: Integer;FRequired: Boolean);
Var FT: TFloatField;
begin
 FT := TFloatField.Create(Self);
 FT.FieldName :=NewFieldName;
 FT.Name := QryBHRpt.Name + FT.FieldName;
 FT.Index := FIndexNo;
 FT.DataSet := QryBHRpt;
 FIndexNo:=FIndexNo+1;
 AddSQLSelect(NewFieldName);
end;


Procedure TfmBHDealReports.ClearTempQueryFieldDefs;
Var I: Integer;
begin
 For I:=QryBHRpt.Fields.Count-1 downto 6 Do
   begin
     QryBHRpt.Fields[I].Free;
   end;
end;

Fri, Apr 2 2010 1:09 AMPermanent Link

Neil Huhta

problem solved.

    my code works as shown - i am using the defunct putersoft pscfilterbox.
that component did not refresh and was overriding my sql with a stale sql
stmt. Once I figured that out - I fixed the Putersoft behavior and now
everything works great.

Neil Huhta










"huhtaman" <nhuhta@digital.net> wrote in message
news:8E942385-BCD5-4C87-9666-3649C978DF0C@news.elevatesoft.com...
> Hello All:
>
>    I have created a report writer based on a TDBISAMQuery component.
> However, to keep things thin, I am dynamically creating most of the query
> at runtime.
>
>    I am running DBISAM 1 - but the structure is all TDataset descendant so
> it sould be the same with all versions.
>
>    I have a query component with the calcfields statically defined so that
> those fields can be compiled in my code. Then, I am adding the fields the
> user is selecting using procedures like MakeFloatfield below.
>
>    I need the fields created so I can hook into Reportbuilder and build a
> report dynamically. Even if I don't - I dont want to change my
> architecture.
>
>    The first time the report runs - it is successful.
>
>    The second time the report runs, it executes code to clean up the
> previously created fields in proc CLEARTEMPQUERYFIELDDEFS - then it
> recreates the fields.
>
>    But - the report always fails the 2nd time. It throws an exception
> saying QryBHRpt: Field 'BMiddle' Not Found. BMiddle is the only field
> added from the first to the second time in the report.
>
>   Anybody know what I am doing wrong here ??? The file has lots of
> fields - so I am trying to keep the query small.
>
> Thank you.
>
> Neil Huhta
>
>
>
>
> procedure TfmBHDealReports.MakeFloatField(NewFieldName, FAction:
> String;FSize: Integer;FRequired: Boolean);
> Var FT: TFloatField;
> begin
>  FT := TFloatField.Create(Self);
>  FT.FieldName :=NewFieldName;
>  FT.Name := QryBHRpt.Name + FT.FieldName;
>  FT.Index := FIndexNo;
>  FT.DataSet := QryBHRpt;
>  FIndexNo:=FIndexNo+1;
>  AddSQLSelect(NewFieldName);
> end;
>
>
> Procedure TfmBHDealReports.ClearTempQueryFieldDefs;
> Var I: Integer;
> begin
>  For I:=QryBHRpt.Fields.Count-1 downto 6 Do
>    begin
>      QryBHRpt.Fields[I].Free;
>    end;
> end;
>
>

Image