The Free Dictionary  
mailing list For webmasters
Welcome Guest Forum Search | Active Topics | Members

How to replace the field type and value in dbgrid? Options
adamlevine
Posted: Sunday, April 1, 2018 10:43:08 PM
Rank: Newbie

Joined: 4/1/2018
Posts: 2
Neurons: 5
How to replace the field type and value in dbgrid?

My SQL query:

Code: XML [Select] DBForm.DBquery.SQL.text:='select callstart, callend, origin, destination, direction from callrecord;

termtype are integer values 0...3, instead I would like to show in dbgrid column fields: None, Incoming, Outgoing or Internal, accordingly. These text values are not stored in any DB table to be joined with; it is also not allowed to add smth to this DB (in my case). Is there a way how to do this "on fly", when the dbgrid obtains the values from the DB?
IMcRout
Posted: Monday, April 2, 2018 2:29:32 AM

Rank: Advanced Member

Joined: 5/27/2011
Posts: 35,382
Neurons: 563,379
Location: Lübeck, Schleswig-Holstein, Germany
Welcome to the forums, adamlevine.

I suspect you're in the wrong section of the wrong forum.
You might be more successful in the Science and Technology 'department'. Good luck.

I totally take back all those times I didn't want to nap when I was younger. (Anon)
leonAzul
Posted: Thursday, April 5, 2018 7:37:11 AM

Rank: Advanced Member

Joined: 8/11/2011
Posts: 8,470
Neurons: 27,478
Location: Miami, Florida, United States
adamlevine wrote:
How to replace the field type and value in dbgrid?

My SQL query:

Code: XML [Select] DBForm.DBquery.SQL.text:='select callstart, callend, origin, destination, direction from callrecord;

termtype are integer values 0...3, instead I would like to show in dbgrid column fields: None, Incoming, Outgoing or Internal, accordingly. These text values are not stored in any DB table to be joined with; it is also not allowed to add smth to this DB (in my case). Is there a way how to do this "on fly", when the dbgrid obtains the values from the DB?


Within DBGrid there is the StringReplace function:

Quote:
Returns a string in which a specified substring has been replaced with another substring.

Declaration:
type TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);

function StringReplace(const S, OldStr, NewStr: string; Flags: TReplaceFlags): string;

Description:
Returns a string in which a specified substring has been replaced with another substring.

If the Flags parameter does not include rfReplaceAll, only the first occurrence of OldStr in S is replaced. Otherwise, all instances of OldStr are replaced by NewStr.
If the Flags parameter includes rfIgnoreCase, the comparison operation is case insensitive.

https://www.thoughtco.com/string-handling-routines-delphi-programming-4092534

To identify the correct substring, you would also need to invoke PosEx function to select which values in the grid you want to apply the substitution to.

You could also take the raw output and |pipe| it through a formatting sequence.

If the output is indeed well-formed XML, an appropriate XSLT style sheet could accomplish the transformation.

Otherwise, it is possible to do this "on the fly" with regular expressions, either through egrep, awk, or other command line utility, or with a shell script written in perl, python, or some other scripting language.

And this, my friend, is why COBOL and RPG are still relevant.
Whistle

"Make it go away, Mrs Whatsit," he whispered. "Make it go away. It's evil."
adamlevine
Posted: Friday, June 8, 2018 2:39:57 AM
Rank: Newbie

Joined: 4/1/2018
Posts: 2
Neurons: 5
Thanks
leonAzul
Posted: Friday, June 8, 2018 9:35:14 AM

Rank: Advanced Member

Joined: 8/11/2011
Posts: 8,470
Neurons: 27,478
Location: Miami, Florida, United States
adamlevine wrote:
Thanks


If you have found a solution, then please show your gratitude by sharing it publicly with others who might have the same problem.

Dancing


"Make it go away, Mrs Whatsit," he whispered. "Make it go away. It's evil."
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS
Forum Terms and Guidelines | Privacy policy | Copyright © 2008-2018 Farlex, Inc. All rights reserved.