Mega Search
23.2 Million


Sign Up

Make a donation  
TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express

DXE5 for a TIBQuery I build a sql at run time , so I have not persistent fields.
For each record I retrieve some values I want to format with the corresponding decimal scale stored in  same record.

Which way can I do it ? which TIBQuery property I need work  with and how ?

Regards
Adalberto Baldini

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 24-Dec-2014, at 5:20 AM EST
From: Adalberto Baldini
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
Adalberto Baldini wrote:
> Thank it works well.
> As I may use the query many times, always building a new SelectSQL and varying the numeber of fields, do I need to clear some memory between a Dataset.Close and new Open?
> Regards Adalberto


No non persistent fields are cleared whenever the query is unprepared and that 
happens whenever you change the SelectSQL.  New Fields will be created when the 
new query is opened which is why you have to re establish OnGetText or 
DisplayFormat properties after opening because it is a new TField.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 2-Jan-2015, at 12:12 PM EST
From: Jeff Overcash (TeamB)
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
Thank it works well.
As I may use the query many times, always building a new SelectSQL and varying the numeber of fields, do I need to clear some memory between a Dataset.Close and new Open?
Regards Adalberto

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 1-Jan-2015, at 11:57 PM EST
From: Adalberto Baldini
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
Adalberto Baldini wrote:
> This works, and I put it in afterscroll event of dataset, but when I change record new format is applied to all records of dataset. I need to format every record with its own format.
> In an app with persistent field I used 
> 
> procedure TDtMd_RegCoge_Frames.IBQry_SdiValDSPSALDOGetText(Sender: TField;
>   var Text: string; DisplayText: Boolean);
> begin
>  Text :=  FormatFloat(fmt[Sender.DataSet.FieldByName('decimal_scale').asinteger
>     + 1],Sender.asFloat) ;
>  DisplayText := True;
> end;
> 
> How could I get same result in a dataset with no persistent fields ?
> 
> Adalberto Baldini

Create your event like normal then in the after open (when the fields are now 
created when not persisted do

   aDataSet.FieldByName().OnGetText := IBQry_SdiValDSPSALDOGetText;



-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 31-Dec-2014, at 8:03 AM EST
From: Jeff Overcash (TeamB)
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
This works, and I put it in afterscroll event of dataset, but when I change record new format is applied to all records of dataset. I need to format every record with its own format.
In an app with persistent field I used 

procedure TDtMd_RegCoge_Frames.IBQry_SdiValDSPSALDOGetText(Sender: TField;
  var Text: string; DisplayText: Boolean);
begin
 Text :=  FormatFloat(fmt[Sender.DataSet.FieldByName('decimal_scale').asinteger
    + 1],Sender.asFloat) ;
 DisplayText := True;
end;

How could I get same result in a dataset with no persistent fields ?

Adalberto Baldini

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 31-Dec-2014, at 2:29 AM EST
From: Adalberto Baldini
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
Adalberto Baldini wrote:
>> Just call FieldByName to get the TField then set the Display property just like 
>> you would if you persist it at design time.
>>
> 
> I tried :
> 
> IBDts_Wk_Bilancio.FieldByName(Fil_Field_List[i]).FieldName.Format := fmt[dec_scl+1];
> 
> but it seems something is wrong, and 
> IBDts_Wk_Bilancio.FieldByName(Fil_Field_List[i]).  has not a displayformat property
> 
> Adalberto

DisplayFormat for number types is introduced at the TNumericField level so you 
have to typecast the TField to TNumericField before setting the DisplayFormat. 
The AfterOpen event is a good place to be setting all these things.

TNumericField(IBDts_Wk_Bilancio.FieldByName(Fil_Field_List[i])).Displayformat := 
fmt[dec_scl+1];

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 27-Dec-2014, at 9:16 AM EST
From: Jeff Overcash (TeamB)
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
> Just call FieldByName to get the TField then set the Display property just like 
> you would if you persist it at design time.
> 

I tried :

IBDts_Wk_Bilancio.FieldByName(Fil_Field_List[i]).FieldName.Format := fmt[dec_scl+1];

but it seems something is wrong, and 
IBDts_Wk_Bilancio.FieldByName(Fil_Field_List[i]).  has not a displayformat property

Adalberto

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 27-Dec-2014, at 3:44 AM EST
From: Adalberto Baldini
 
Re: TIBQuery formatting a field at run time  
News Group: embarcadero.public.delphi.database.interbase_express
Adalberto Baldini wrote:
> DXE5 for a TIBQuery I build a sql at run time , so I have not persistent fields.
> For each record I retrieve some values I want to format with the corresponding decimal scale stored in  same record.
> 
> Which way can I do it ? which TIBQuery property I need work  with and how ?
> 
> Regards
> Adalberto Baldini

Just call FieldByName to get the TField then set the Display property just like 
you would if you persist it at design time.

FYI, TIBDataset is more efficient than TIBQuery.  TIBQuery should only really be 
used if you are migrating a BDE app, otherwise there is no reason to use it.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 24-Dec-2014, at 9:08 AM EST
From: Jeff Overcash (TeamB)