Solved

How do I get current field name ?

Posted on 2000-03-28
8
275 Views
Last Modified: 2010-04-04
I have created a form with a number of fields on it, and want to know how do I get the name of the current field being edited, or focused, without writing code for every field component on the form ?

I can do this in a DBGrid easy enough, but am unable to apply the same code to the form.
0
Comment
Question by:pjelias
8 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2666024
Use TForm.ActiveControl like this:

TheActiveControlName := ActiveControl.Name;

Cheers,

Raymond.
0
 

Author Comment

by:pjelias
ID: 2667381
Have already tried that. The Problem is I am using a FRAME (Delphi 5) that appears on a Form. When I attach the code to the Frame, nothing happens. When I attach code to the Main Form containing the Frame, all other objects names are accessible but not the frame or object within the Frame ?

The Use of Frames has solved alot of problems, but has caused a number of others.

I was thinking of code more related to the Table or Data Components, which can detect field movements/changes etc.

Thanks for your response anyway.
0
 

Author Comment

by:pjelias
ID: 2667393
Adjusted points from 50 to 100
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2668691
Hello,
are you talking about knowing wich of your
ttable field is beeing edited ?
Is suggest you use the ondatachange event
of you datasource :
extracted from the help file ...

Occurs when the current record has been edited and the application moves from one field or record to another in a dataset associated with the data source component.

type TDataChangeEvent = procedure(Sender: TObject; Field: TField) of object;
property OnDataChange: TDataChangeEvent;

Description

Write an OnDataChange event handler to take specific actions when a field in the current record has been edited and an application moves from one field or record to another in a dataset associated with a data source component. For example, methods that can trigger this event include the Next or Prior methods for the dataset.

Data-aware controls notify a data source of a data change because of:

Scrolling to a new record.
      Modifications to a field’s data.

The Field parameter is nil if more than one of the fields changed simultaneously, such as when moving from one record to another. Otherwise, Field indicates the edited field.

OnDataChange is especially useful in applications that must synchronize data display in controls that are not data aware.
what do you think of that ?
0
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.

 

Accepted Solution

by:
JimboKern69 earned 100 total points
ID: 2669899
This seemed to do the trick...

First some details:

I created a main form, then two sub-frames that I placed on the main form.

The Main Form also has a label who's caption will be the currently focused control.

What I did was create another Interface (TFieldFrame) which each sub-form will implement.  This interface has a single method - GetFieldName(fld:Integer):String;

The main form can then hook in to the active frame and using a generic onEnter and onExit methods, which control is active and get the names.

Instead of posting all the code, which is extensive, I'll send you to a web-site to get the sample D5 project I created.

http://kernsoft.freeservers.com/FieldNames.html

Hope this helps.

Jim Kern
0
 

Expert Comment

by:JimboKern69
ID: 2669908
BTW...I didn't mean to make it look like there is a lot of code to get this done...there is for the initial setup, but then, to add additional frames and/or controls, there is not much to do at all...really.

Anyway...hope it helps.

Jim Kern
0
 

Author Comment

by:pjelias
ID: 2671600
This appears to work well and will be of benefit in future apps, but, I have tried the code in the problem app and have found another hurdle.

I am using a Third Party Component from Infopower 2000 - A RecordView Panel - which after setting a number of options, creates a nicely formatted ViewPanel with Fields and Labels displayed.

Unfortunately, there is no way to attach code to each Edit Box/Component to return the TAG Value, as these components do not exist within the panel.

********************************************************
Have just found a workaround for the problem in preceding paragraph, by creating Infopower Edit/Comboboxes, and then assigning these to each field via Custom Edit option in the Control Type Dialog.
********************************************************

Will give you the points anyway, as the sample app you supplied looks very useful for future apps.

Thanks

0
 

Expert Comment

by:JimboKern69
ID: 2672996
You are welcome...thanks for the grade as well.

Actually, this will also come in handy for myself in future apps, so I will certainly be keeping this code around for some time now.

Note: In about a month I will probably take the code off that web-site, so if the above link is no longer active, feel free to e-mail kernsoft@juno.com for the code or any other questions you may have about it.

Thanks

Jim Kern
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

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 76
Connection between libmysql.dll and MySQL Versions 7 87
SUM 2 INTEGER ARRAYS INTO 1 10 92
Dynamically Created Query 3 48
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
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…

947 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

21 Experts available now in Live!

Get 1:1 Help Now