创建引用它们的新对象 [英] creating new objects with references to them

查看:62
本文介绍了创建引用它们的新对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我想做的事情是程序员每天都要处理
,但我想不出办法。基本上,我是写b数据库前端的b $ b,我想要一个新的研究员。当用户按下新记录时,创建对象

。按钮。他可以根据需要随时打开

多个新记录并填写信息。


我不知道怎么办是处理这个任意数量的对象。

当需要将数据保存到数据库时,如何访问每个

对象(以获取与每个对象关联的文本字段) )?我不是必须

给每个实例一些名字?或者还有其他一些方法可以做这个吗?每次用户按下New

Record时,只需创建一个新实例即可。不够好,因为我如何在程序过程中保留对该实例的引用,即使在第二个或第二个
第三个实例之后也是如此创造了?


希望这是有道理的。这似乎是一项普遍的任务。


谢谢。

解决方案

JohnJSal写道:


似乎我想做的是程序员每天处理
的事情,但我只是想不到这样做的方式。基本上,我是写b数据库前端的b $ b,我想要一个新的研究员。当用户按下新记录时,创建对象

。按钮。他可以根据需要随时打开

多个新记录并填写信息。



似乎很简单。


我不知道如何处理这个任意数量的对象。

当需要将数据保存到数据库时,如何访问每个

对象(以获取与每个对象关联的文本字段)?我不是必须

给每个实例一些名字?或者还有其他一些方法可以做这个吗?每次用户按下New

Record时,只需创建一个新实例即可。不够好,因为我如何在程序过程中保留对该实例的引用,即使在第二个或第二个
第三个实例之后也是如此已创建?



从一个空列表开始,并向其添加新实例。然后当

用户表示完成时,您可以遍历列表,将它们插入数据库中(大概是先插入新研究员的详细信息)。


为了最大限度地减少一致性问题,将所有这些

插入作为单个数据库事务进行处理。


希望这是有道理的。这似乎是一项常见的任务。



问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://holdenweb.blogspot.com

最近的Ramblings http://del.icio.us/steve.holden


In< 11 **** ******************@b28g2000cwb.googlegroups .com> ;, JohnJSal

写道:


我不知道怎么做才能处理这个任意数量的对象。

当需要将数据保存到数据库时,如何访问每个对象

对象(获取与每个文本字段关联的文本字段)?我不是必须

给每个实例一些名字?或者还有其他一些方法可以做这个吗?每次用户按下New

Record时,只需创建一个新实例即可。不够好,因为我如何在程序过程中保留对该实例的引用,即使在第二个或第二个
第三个实例之后也是如此产生的?



将对象放入列表中。每次用户按下新建按钮

都会附加一个新的研究人员对象。


Ciao,

Marc' 'BlackJack''Rintsch





11月2日下午3:15,JohnJSal < johnj ... @ gmail.comwrote:


看起来我想做的是程序员每天要处理的事情

每天,但我想不出办法。基本上,我是写b数据库前端的b $ b,我想要一个新的研究员。当用户按下新记录时,创建对象

。按钮。他可以根据需要随时打开

多个新记录并填写信息。


我不知道怎么办是处理这个任意数量的对象。

当需要将数据保存到数据库时,如何访问每个

对象(以获取与每个对象关联的文本字段) )?我不是必须

给每个实例一些名字?



这完全取决于你使用的UI(Web前端?GUI,例如

Tkinter?)以及你的用例是什么。


你想要做什么?创建一堆研究员

对象,然后将它们保存在一个单击中?创建一个

研究人员列表,然后选择要保存到数据库中的哪个?从数据库中填充一个

研究人员的列表,并可以选择编辑或添加新的

?新的Researcher对象是否应该在保存时尽快提交给数据库




无论如何,一个简单的研究人员列表应该足以满足这些要求

的目的,并且假设你想要一次性提交它们,你就有了b / b
a准备迭代的对象列表。


It seems like what I want to do is something that programmers deal with
everyday, but I just can''t think of a way to do it. Basically, I am
writing a DB front-end and I want a new "Researcher" object to be
created whenever the user presses the "New Record" button. He can open
as many new records at a time as he wants and fill in the information.

What I don''t know how to do is handle this arbitrary number of objects.
When it comes time to save the data to the DB, how do I access each
object (to get the text fields associated with each)? Won''t I have to
have given each instance some name? Or is there some other way to do
this? Simply creating a new instance each time the user presses "New
Record" won''t be good enough, because how do I retain a reference to
that instance over the course of the program, even after a second or
third instance has been created?

Hope that makes sense. It seems like such a common task.

Thanks.

解决方案

JohnJSal wrote:

It seems like what I want to do is something that programmers deal with
everyday, but I just can''t think of a way to do it. Basically, I am
writing a DB front-end and I want a new "Researcher" object to be
created whenever the user presses the "New Record" button. He can open
as many new records at a time as he wants and fill in the information.

Seems straightforward.

What I don''t know how to do is handle this arbitrary number of objects.
When it comes time to save the data to the DB, how do I access each
object (to get the text fields associated with each)? Won''t I have to
have given each instance some name? Or is there some other way to do
this? Simply creating a new instance each time the user presses "New
Record" won''t be good enough, because how do I retain a reference to
that instance over the course of the program, even after a second or
third instance has been created?

Start with an empty list, and append new instances to it. Then when the
user indicated completion you can iterate over the list INSERTing them
into the database (presumably INSERTing the new researcher''s details first).

To minimize consistency problems it would help to make all of these
insertions as a single database transaction.

Hope that makes sense. It seems like such a common task.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden


In <11**********************@b28g2000cwb.googlegroups .com>, JohnJSal
wrote:

What I don''t know how to do is handle this arbitrary number of objects.
When it comes time to save the data to the DB, how do I access each
object (to get the text fields associated with each)? Won''t I have to
have given each instance some name? Or is there some other way to do
this? Simply creating a new instance each time the user presses "New
Record" won''t be good enough, because how do I retain a reference to
that instance over the course of the program, even after a second or
third instance has been created?

Put your objects into a list. Each time the user presses the `New` Button
append a new researcher object to it.

Ciao,
Marc ''BlackJack'' Rintsch




On Nov 2, 3:15 pm, "JohnJSal" <johnj...@gmail.comwrote:

It seems like what I want to do is something that programmers deal with
everyday, but I just can''t think of a way to do it. Basically, I am
writing a DB front-end and I want a new "Researcher" object to be
created whenever the user presses the "New Record" button. He can open
as many new records at a time as he wants and fill in the information.

What I don''t know how to do is handle this arbitrary number of objects.
When it comes time to save the data to the DB, how do I access each
object (to get the text fields associated with each)? Won''t I have to
have given each instance some name?

It all depends on what UI you are using (Web frontend? GUI such as
Tkinter?) and what your use case is.

What is it exactly that you want to do? Create a bunch of Researcher
objects and then save them in a single hit? Create a list of
Researchers and then choose which to save to the db? Populate a list of
researchers from the db, and have the option of editing or adding new
ones? Should the new Researcher objects be committed to the db as soon
as they are saved?

Anyway, a simple list of Researchers should suffice for any of these
purposes, and assuming you want to commit them all in one hit, you have
a list of objects ready to iterate over.


这篇关于创建引用它们的新对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆