Solved

Delphi Forms

Posted on 2012-03-26
5
322 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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