Solved

Delphi Forms

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
FMX and jaudiotracker playing memory stream 29 98
Multi-layered image in FireMonkey 9 68
IP without any Dots 1 62
Using MMsystem To change audio input 1 21
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

696 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