Recent

Author Topic: Add buttons and memo's runtime  (Read 2088 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 602
Add buttons and memo's runtime
« on: October 23, 2016, 01:26:14 pm »
Currently I have the following. A page control with a number of tabs. Per tab a number of buttons whith queries that are performed on a database. In another window is a memo per query in which the query can be maintained.
If need to add a new query to the tool i must make a button, create a memo and send a new executable to the user.

How can I make sure that a user can create runtime buttons  and memos and perhaps also make  tabs on the page control. If that is possible a user can expand the tool himself.

One suggestion I received was to create an ini file, and it indicate whether button, page control and memo is added. And read this ini read every start.

What is a good way to do this?

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Add buttons and memo's runtime
« Reply #1 on: October 23, 2016, 01:52:53 pm »
One suggestion I received was to create an ini file, and it indicate whether button, page control and memo is added. And read this ini read every start.
Yes, I think that's the way to go.
You can create dynamic array / TFPGObjectList list of buttons/memos.
OR maybe even better. Just to fill-in each page dynamically and free its content "on tab switch" (that'll reduce memory consumption, but will increase CPU load). Some objects can be even re-used (just moving memo/buttons to a new tab and assigning their new properties)
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Add buttons and memo's runtime
« Reply #2 on: October 23, 2016, 11:50:56 pm »
If need to add a new query to the tool i must make a button, create a memo and send a new executable to the user.

How can I make sure that a user can create runtime buttons  and memos and perhaps also make  tabs on the page control. If that is possible a user can expand the tool himself.
Usually (and i meant that in the general sense of the word) the need to add extra components to 'expand' your user interface is an indication that you're doing something wrong.

Ask yourself the (theoretical) question: What if my user starts adding 1 million additional queries, how would my application/tool look like.

Quote
One suggestion I received was to create an ini file, and it indicate whether button, page control and memo is added. And read this ini read every start.
If you want to use a .ini for distribution (e.g. you want to upgrade end-user product by providing such .ini) then perhaps you could use a .ini file for that. Storing (additional) queries and have something like that accessible for the user, please no (ini files are easy to manipulate by end-users and as such can make your program crash, especially in the case of queries).

imho it would be better to store (additional) queries in a separate table. You are working with them already so, why no use them ?

Do note that databases are definitely not my area of expertise.
« Last Edit: October 23, 2016, 11:57:54 pm by molly »

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add buttons and memo's runtime
« Reply #3 on: October 24, 2016, 12:09:14 am »
Usually (and i meant that in the general sense of the word) the need to add extra components to 'expand' your user interface is an indication that you're doing something wrong.

Yes, I would strongly agree.

I would move your "standard" queries out of the program too. Put them in an .ini file that is installed alongside the program so less likely that it would be messed with.

Display all query descriptions in a list. When the user clicks on a list item, the query is displayed in a TMemo. Have a Run button or whatever it is you're trying to do with the query.

Add a New button that brings up a dialog that prompts for a new query description and query. This is added to list and saved in a second .ini file somewhere in a user-writable part of file system. When program starts it needs to load both .ini files.

Ideally you would have some way of doing a check of syntax on the entered query. Absent that, at least make sure you can recover from any exception raised by a bad query.

Also, how do you prevent a user's query from changing database contents if you don't want that?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Add buttons and memo's runtime
« Reply #4 on: October 24, 2016, 11:53:09 pm »
The attached project shows a GUI that provides for dynamic addition of queries, based on a pagecontrol.
It is a GUI skeleton. The database part is not actually connected in this demo, so you would need to adapt the datamodule in this demo to use it with a live database.
Production code would need to check user SQL queries for errors, or possibly only allow a user to choose from a list of valid pre-written queries, etc. etc.

For all its shortcomings it may, however, give you some ideas.

 

TinyPortal © 2005-2018