简体   繁体   English

Delphi创建用户表单

[英]Delphi create User form

I am making a user form in Delphi for documents tracking application. 我在Delphi中制作了一个用户表单 ,用于文档跟踪应用程序。 I am interested in functionalities input new entry (record) and view list by... (date, name of document, ID,...) . 我对功能感兴趣,请输入新条目(记录)并按...(日期,文档名称,ID等)查看列表

My problem is that I don't know how to implement these functionalities for more than one user. 我的问题是,我不知道如何为多个用户实现这些功能。 Currently, I have 5 users. 目前,我有5个用户。 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, eg: 请注意,我不希望在应用程序的代码中静态分配用户,例如:

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 . 注意:我正在将dbExpress工具与带有RAD Studio XE7 Architect的 MySQL DBMS一起使用。

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. 这些在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. 熟悉M-> D关系后,我想您会意识到,您应该问的是如何在应用程序中进行设置,而不是将单个用户硬编码到表单中的问题。

In your case, what you are missing at the moment is a table of users' details. 对于您而言,目前缺少的是一张用户详细信息表。 Let's call that the Users table. 我们称其为Users表。 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. 通常,通常,其中将包含其名称,以及某种独特的标识符(最好是Users数据库表中的“主键”),但请不要包含其访问数据库的密码,尤其是非纯文本格式的密码。

Once your Users table is created, you can create a display grid (TDBGrid) and input/editing form for it. 创建用户表后,即可创建显示网格(TDBGrid)并为其输入/编辑表单。

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). 一旦完成,剩下要做的就是在Delphi项目中设置Users表(主表)和Documents表(明细表)之间的Master-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. 广义上讲,这是将TDataSource连接到Users表并设置Documents表的DataSource(或MasterSource)属性指向Users TDataSource的问题,然后设置Documents的其他两个依赖于表类型的属性表。

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. D7之前的每个版本的Delphi都带有一个演示应用程序“ MastApp”,该应用程序说明了如何在多个表之间使用主从关系。 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. 我建议您看一下您的Delphi版本的MastApp,然后研究如何为实际使用的Delphi数据集的类型设置M-> D关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM