0

I am making a user form in Delphi for documents tracking application. I am interested in functionalities input new entry (record) and view list by... (date, name of document, ID,...).

My problem is that I don't know how to implement these functionalities for more than one user. Currently, I have 5 users. Each user has a unique input data (record) fields (columns) and view fields (columns) of each user are also unique. There could be more users.

So, how to implement these functionalities for this form? How to assign different data (fields) for each separate user for input and view? That is what I don't understand. Is that distributed functionality of an application? If yes, how to achieve it?

Note that I don't want static assigning of a user in application's code, e.g:

if(username='user1') then {
input();
view();
}
else if (username='user2') then {...}
...

because, than, every time there is a new user, developer must go back to the application's code and hard-code it. That is not efficient and is a bad implementation. Rather, I want that to be dynamic (if that is the right term). How to achieve this?

Note: I am using dbExpress tool with MySQL DBMS with RAD Studio XE7 Architect.

3
  • "developer must go back to the application's code and hard-code it." Not at all! The way to do this is to have in your db a table of users and their details. Then you write your document tracking code to handle the user which is the current record in the Users table. You shouldn't require any conditional tests on a user's identity in your code at all. Commented May 2, 2018 at 9:16
  • @MartynA, Could you show a concrete code sample or give a reference on it? I really don't know how to do this. Commented May 2, 2018 at 9:19
  • 1
    There are dozens of Delphi examples of this here on SO. Try searching for them. Commented May 2, 2018 at 9:38

1 Answer 1

4

If I'm correctly understanding what you are asking, it seems as if you are unfamiliar with the idea of tables/datasets which operate in a so-called Master-Detail relationship. These are very easy to set up in Delphi.

Once you get familar with M->D relationships, I think you'll realise that what you should have been asking about is how to set one up in your app, rather than the problem of hard-coding of individual users into your form.

In your case, what you are missing at the moment is a table of users' details. Let's call that the Users table. Usually this would contain their name, obviously, and some kind of unique identifier (best is a "Primary key" in the Users database table), but NOT, please, their password to access the db, especially not in plain text.

Once your Users table is created, you can create a display grid (TDBGrid) and input/editing form for it.

Then, if you don't have it already, you could set up a grid and editing form for users' documents (which I'm going to refer to as the Documents table).

Once that's done, the main thing left to do is to set up in your Delphi project a Master-Detail relationship between your Users table (the master) and your Documents table (the detail).

If you prefer you can have a single form with two grids, the Users grid and the Documents grid on it, and as you scroll through the Users grid, you'll see that the Documents grid shows only their document records.

The details of how to set up a Master-Detail vary somewhat according to the type of table/dataset you're using so you'll need to search online for the details of how to do it. Broadly, it's a matter of connecting a TDataSource to your Users table and setting the DataSource (or MasterSource) property of your Documents table to point at the Users TDataSource, and then setting a couple of other, table-type-dependent properties of the Documents table.

Every edition of Delphi since well before D7 has come with a demo app, "MastApp" which illustrates how you use Master-Detail relationship amongst a number of tables. I suggest you take a look at the MastApp for your Delphi version and then look into how to set up M->D relationships for the type of Delphi dataset you are actually using.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.