?
Solved

Delphi Forms

Posted on 2012-03-26
5
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

741 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