Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi Forms

Posted on 2012-03-26
5
Medium Priority
?
330 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

610 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