?
Solved

How to setup a user manipulated edit field?

Posted on 2003-03-29
4
Medium Priority
?
143 Views
Last Modified: 2010-04-04
Hello,

I have a cool database program written in Delphi2 that allows a user to enter a bunch of data then get averages and stuff back. But I would like for the user to be able to type their name in a field next to the database somewhere in order to personalize it.
If I use a standard edit field it loses the data each time the program is closed then opens blank. How can I put a field in my program that accepts the users' name and saves it?

Thanks in advance!
0
Comment
Question by:lontek
  • 3
4 Comments
 
LVL 1

Expert Comment

by:grolschisgood
ID: 8233252
you have several options available

1.  write the name into the windows registry
2. save it into a text file in your program directory
3. save it into the same database as the other data.  either into a different table or against each record of data that the user enters.

whats your pref i give you a hand



0
 
LVL 1

Author Comment

by:lontek
ID: 8242226
Hi,
Number 2 looks like a nice way to do it. Please inform and
I will plan to give it a try!

Thanks.
0
 
LVL 1

Expert Comment

by:grolschisgood
ID: 8245008
as a quick way to provide simple setup information to a application i sometimes use a text file (with same name as executable eg myprog.exe and myprog.txt) with information it it like

NAME=<data>
DESCRIPTION=<data>

where name and description act like fields in a database.  This method is setting up name value pairs.

you need the following global variables setup

FSetupInfo : Tstrings;
SetupFileName : string;

then use the following code to read the txt file of the same name as my application into my Tstring list

  FSetupInfo:=TStringList.Create;
  SetupFileName:=ChangeFileExt(Application.ExeName, '.TXT')
  if FileExists(SetupFileName) then
    FSetupInfo.LoadFromFile(SetupFileName);
  else WriteLast('Configuration file is missing.');

once loaded you can refer to the values of any of the "fields" using the following...

Edit1.text:=FSetupInfo.Values['DESCRIPTION'];

change a value of one of the "fields" with ...

FSetupInfo.Values['DESCRIPTION']:=Edit2.text;

and then save the changes back to the config file with

FSetupInfo.SavetoFile(SetupFileName);

this is basically a INI file but without groups.  Search for INI Files in delphi help for an easy example of using INI files.

each user with the applicaiton installed on their computer can save their personal details into this file

hope this helps


0
 
LVL 1

Accepted Solution

by:
grolschisgood earned 150 total points
ID: 8245009
as a quick way to provide simple setup information to a application i sometimes use a text file (with same name as executable eg myprog.exe and myprog.txt) with information it it like

NAME=<data>
DESCRIPTION=<data>

where name and description act like fields in a database.  This method is setting up name value pairs.

you need the following global variables setup

FSetupInfo : Tstrings;
SetupFileName : string;

then use the following code to read the txt file of the same name as my application into my Tstring list

  FSetupInfo:=TStringList.Create;
  SetupFileName:=ChangeFileExt(Application.ExeName, '.TXT')
  if FileExists(SetupFileName) then
    FSetupInfo.LoadFromFile(SetupFileName);
  else WriteLast('Configuration file is missing.');

once loaded you can refer to the values of any of the "fields" using the following...

Edit1.text:=FSetupInfo.Values['DESCRIPTION'];

change a value of one of the "fields" with ...

FSetupInfo.Values['DESCRIPTION']:=Edit2.text;

and then save the changes back to the config file with

FSetupInfo.SavetoFile(SetupFileName);

this is basically a INI file but without groups.  Search for INI Files in delphi help for an easy example of using INI files.

each user with the applicaiton installed on their computer can save their personal details into this file

hope this helps


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question