Solved

Delphi Forms

Posted on 2012-03-26
5
324 Views
Last Modified: 2012-06-22
Hi
When user clicks nbinsert button from dbnavigator, how do I assign a default string value to a field on a form?

E.g. user inserts a new record on Form A so I need to enter "FormA" as default to field Form_Type.
If user inserts a new record on Form B, I need to enter "FormB" as default to field Form_Type.
etc.
0
Comment
Question by:kevincox29
  • 3
5 Comments
 
LVL 4

Expert Comment

by:MichaelStaszewski
ID: 37766359
Try this. Implement the OnBeforeAction event handler for your navigator. In there...

if Button = nbInsert then
  Set default value;

Open in new window

0
 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 37768400
Use OnNewRecord event of your clientdataset.

Assuming that your clientdataset is in a DataModule then you can go like this...

  procedure TDataModule1.ClientDataSet1NewRecord(DataSet: TDataSet);
  begin
    DataSet.FieldByName('Form_Type').AsString := Screen.ActiveForm.Name;
  end;

Open in new window

0
 
LVL 4

Expert Comment

by:MichaelStaszewski
ID: 37768427
Ah. "Field" being key word there. My brain failed to operate properly and I was thinking the OP wanted to do something to a form control prior to inserting a new record. +1 to Thommy's solution.
0
 

Author Comment

by:kevincox29
ID: 37770184
Currently I am using:

if Button = nbInsert then
  Set default value;

But it's a hit and a miss. When user posts the record, default value is seen on form but sometimes value does not get saved to the table field. No errors/messages displayed.
0
 
LVL 4

Expert Comment

by:MichaelStaszewski
ID: 37771528
Ignore my suggestion. Thommy's solution is the way to go. My brain wasn't with me when I replied. Typically I use the OnBeforeAction to prevent a dataset action to occur under certain circumstances. It should not be used to initialize a field's value.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now