Recent

Author Topic: Non-visual String Manager Component  (Read 5680 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Non-visual String Manager Component
« on: November 03, 2018, 07:57:27 am »
G'day,

Before I sit down and reinvent the wheel - does anyone know if we have a string manager component tucked away somewhere?  Something I can plonk on a data module, then load in a bunch of SQL statements?  Ideally, I'd like:
  • Each string to be referenced by name, though I can live with accessing it via index..
  • I'd like each string to be able to be multi-line. 
  • In an ideal work I'd like to be able to define which syntax parser to use when editing the strings this component is managing.  HTML and SQL are the main two I can think of.  But yeah - this requirement is a nice to have

At the moment I have a few support units chock full of stuff like:
Code: Pascal  [Select][+][-]
  1.    SQL_EQUIPMENT_HISTORY: String =
  2.     'SELECT ' +
  3.     '  EH.EQUIPMENT_ID, ' +
  4.     '  EH.EQUIPMENT_HISTORY_ID, ' +
  5.     '  CASE  ' +
  6.     '    WHEN EH.PARENT_EQUIPMENT_ID IS NULL THEN '''' ' +
  7.     '    ELSE PED.EQUIPMENT_TYPE||'' [''||PED.SERIAL_NUMBER||'']'' ' +
  8.     '  END AS "PARENT", ' +
  9.     '  PKG_CHEV_EQUIPMENT.LOCATION(ED.SERIAL_NUMBER, EH.DATE_INSTALLED) AS "PARENT_LOCATION", ' +
  10.     '  EH.ACOMMENT AS "COMMENT", ' +
  11.     '  EH.DATE_INSTALLED, ' +
  12.     '  EH.DATE_REMOVED ' +
  13.     'FROM EQUIPMENT_HISTORY EH ' +
  14.     'INNER JOIN EQUIPMENT_DETAILS ED ON (ED.EQUIPMENT_ID=EH.EQUIPMENT_ID) ' +
  15.     'LEFT JOIN EQUIPMENT_DETAILS PED ON (PED.EQUIPMENT_ID=EH.PARENT_EQUIPMENT_ID) ' +
  16.     'WHERE EH.EQUIPMENT_ID=:EQUIPMENT_ID ' +
  17.     'ORDER BY EH.DATE_INSTALLED ';  


Managing all these strings in code is as painful as it looks.

Many thanks

Mike
« Last Edit: November 03, 2018, 07:59:36 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Non-visual String Manager Component
« Reply #1 on: November 03, 2018, 08:52:28 am »
Code: Pascal  [Select][+][-]
  1. program simple;
  2. {$mode delphi}
  3. uses classes, generics.collections;
  4. type
  5.   Tmystringmanager = Tdictionary<string,Tstringlist>;
  6. begin
  7. end.

Or if you prefer fgl over rtl generics:
Code: Pascal  [Select][+][-]
  1. program simple;
  2. {$mode delphi}
  3. uses classes, fgl;
  4. type
  5.   Tmystringmanager = TfpgMap<string,Tstringlist>;
  6. begin
  7. end.

Now you can use the indexing features of the dictionary/map and all Tstringlist features are available to manipulate the contents.

But you can also use e.g. a (couple of) TBufDataset to store indentifier, strings and highlighter.
« Last Edit: November 03, 2018, 09:06:31 am by Thaddy »
Specialize a type, not a var.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Non-visual String Manager Component
« Reply #2 on: November 03, 2018, 10:59:34 am »
Now you can use the indexing features of the dictionary/map and all Tstringlist features are available to manipulate the contents.

But you can also use e.g. a (couple of) TBufDataset to store indentifier, strings and highlighter.

Thanks - if the component doesn't already exist I'll look at what you suggest in my implementation.

I may have confused the issue by asking for a non-visual component.  Sorry about that.  What I meant was a design-time component that manages strings.    I'm not keen on using string resources, and I'm trying to get away from having several units chock full of multi-line string constants. 
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Non-visual String Manager Component
« Reply #3 on: November 03, 2018, 11:44:09 am »
It is very easy to write a TStringContainer component based on a TStringlist. There are already many components that have strings properties, basically factor out the designtime code from one of these and you're almost done. Alternatively, use a TBufDataset and put it in a little local database app. That's really easy and readily available. Or use a TInifile
Specialize a type, not a var.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Non-visual String Manager Component
« Reply #4 on: November 03, 2018, 03:07:00 pm »
Yes the Tinifile works well because you can write it to a stream instead of directly file and thus use a Memory stream instead for speed,
later to file it  if you wish...

 But in reality one could simply use a Tmemo hidden to later use as a quick reference to see what's in the list as an option of the program..

 Memo has the line property that gives you direct access of course via an  index etc...
The only true wisdom is knowing you know nothing

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Non-visual String Manager Component
« Reply #5 on: November 04, 2018, 06:33:45 am »
Inifile/xml/json means making the SQL available to the end user - same with unencrypted SQLite, and SQLite is overkill anyway.  I vaguely considered dumping a series of text files into a zip file, but again seems overkill.
I considered TMemo with one line per SQL, won't be a pretty solution though (I prefer my SQLs presented multi-line)

It's easy to implement a TComponent descendant that does what I want, I just didn't want to do spend the time if we we already had something similar in Lazarus CCR.   Seeing as how other responses are around implementation detail rather than confirming if the wheel exists, I'll assume there isn't such a component.

Many thanks :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Non-visual String Manager Component
« Reply #6 on: November 04, 2018, 08:17:55 am »
Inifile/xml/json means making the SQL available to the end user - same with unencrypted SQLite, and SQLite is overkill anyway.  I vaguely considered dumping a series of text files into a zip file, but again seems overkill.
I considered TMemo with one line per SQL, won't be a pretty solution though (I prefer my SQLs presented multi-line)

It's easy to implement a TComponent descendant that does what I want, I just didn't want to do spend the time if we we already had something similar in Lazarus CCR.   Seeing as how other responses are around implementation detail rather than confirming if the wheel exists, I'll assume there isn't such a component.

Many thanks :-)
if my memory serves me right there was a string manager in one of the turbo power products (turbo power essentials or orpheus) I have no idea if the port to lazarus inlcude that component so.....
In nay case I use the unit approach you've shown too if you want to make things a bit more develop time manageable you can have all the single sqls as single files in a directory and include them in your unit for example
Code: Pascal  [Select][+][-]
  1.     SQL_EQUIPMENT_HISTORY: String = {$I EQP_History.inc}
  2.  
EQP_History.inc will contain
Code: [Select]
        'SELECT ' +
        '  EH.EQUIPMENT_ID, ' +
        '  EH.EQUIPMENT_HISTORY_ID, ' +
        '  CASE  ' +
        '    WHEN EH.PARENT_EQUIPMENT_ID IS NULL THEN '''' ' +
        '    ELSE PED.EQUIPMENT_TYPE||'' [''||PED.SERIAL_NUMBER||'']'' ' +
        '  END AS "PARENT", ' +
        '  PKG_CHEV_EQUIPMENT.LOCATION(ED.SERIAL_NUMBER, EH.DATE_INSTALLED) AS "PARENT_LOCATION", ' +
        '  EH.ACOMMENT AS "COMMENT", ' +
        '  EH.DATE_INSTALLED, ' +
        '  EH.DATE_REMOVED ' +
        'FROM EQUIPMENT_HISTORY EH ' +
        'INNER JOIN EQUIPMENT_DETAILS ED ON (ED.EQUIPMENT_ID=EH.EQUIPMENT_ID) ' +
        'LEFT JOIN EQUIPMENT_DETAILS PED ON (PED.EQUIPMENT_ID=EH.PARENT_EQUIPMENT_ID) ' +
        'WHERE EH.EQUIPMENT_ID=:EQUIPMENT_ID ' +
        'ORDER BY EH.DATE_INSTALLED '; 
on a second thought write your own component make sure that you can link it to a connection/database and test execute each sql. and if you find time you can even use synedit to highlight the sql while editing.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: Non-visual String Manager Component
« Reply #7 on: November 04, 2018, 12:13:49 pm »
Inifile/xml/json means making the SQL available to the end user - same with unencrypted SQLite, and SQLite is overkill anyway.  I vaguely considered dumping a series of text files into a zip file, but again seems overkill.
I considered TMemo with one line per SQL, won't be a pretty solution though (I prefer my SQLs presented multi-line)

It's easy to implement a TComponent descendant that does what I want, I just didn't want to do spend the time if we we already had something similar in Lazarus CCR.   Seeing as how other responses are around implementation detail rather than confirming if the wheel exists, I'll assume there isn't such a component.

Many thanks :-)
If you want to use an INIFile that has encrypted entries, you can use CryptINI (in OPM and ccr).  It can also encrypt/decrypt the whole inifile as well on form.create/close.
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Non-visual String Manager Component
« Reply #8 on: November 04, 2018, 04:57:20 pm »
I think the best solution would be to make a custom display just for this SQL text so it displays as you wish...

Drop a TScrollBox on some component or form somewhere and implement the scrolling and view port of the text with the format as you
wish..

 I just wrote something like that not to long ago. I supported the scrollbars, highlighting etc..

 You may even be able to do something with TSynEdit etc..
The only true wisdom is knowing you know nothing

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: Non-visual String Manager Component
« Reply #9 on: November 05, 2018, 09:55:21 pm »
see TRxTextHolder in RxFPC. New component at revision 6710.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Non-visual String Manager Component
« Reply #10 on: November 06, 2018, 04:55:23 am »
see TRxTextHolder in RxFPC. New component at revision 6710.

This is exactly what I was looking for, many thanks!
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018