Delphi 2.0 cursor handling

Delphi 2.0 cursor handling

How can I get the cursor to advance to the next form field after a field has been filled with the maximum number of characters? I am using Delphi 2.0.

Hmm… sounds like a serial number entry thing to me. Whatever the case,the best way I’ve found to handle this is to use the OnChange method of theTEdit to determine the length of the text being entered at runtime. Then ifthe text has reached a specified length, call Self.ActiveControl to move toa specific control.

For example, I have an application that requires thatthe user enter a social security number separated by three fields. Insteadof having the user press Tab to move from field to field, I trap the OnChangeevent handler to determine the length of the text and move to the next editcontrol if the text for the field in question reaches a certain size. Here’sthe code for my social security number entry:

procedure PatientForm.edSSNBegChange(Sender: TObject);begin  case TEdit(Sender).Tag of    100 : if Length(TEdit(Sender).Text) = 3 then            ActiveControl := edSSNMid;    101 : if Length(TEdit(Sender).Text) = 2 then            ActiveControl := edSSNEnd;    102 : if Length(TEdit(Sender).Text) = 4 then            ActiveControl := Button1;  end;end;
On the form where this method lives, I have three edit boxes called edSSNBeg, edSSNMid and edSSNEnd to signify the first, middle, and end parts ofa social security number. As you may know, a social security number isdefined as a three-digit front plus a two-digit middle and a four-digit end. The codeabove captures this quite well.

Notice that I use the Tag property for the edit boxes. Each one has aspecific tag value so the procedure can determine which editbox is currently active, because TEdit(Sender) doesn’t tell you much. So byusing the Tag property, I can save myself a lot of coding by using a casestatement.

With respect to what decides whether the cursor should move, eachcase condition checks for the length of the current edit box’s text usingthe Length property. If has reached the size specified, the cursor is movedto the next field.

Why does this work? OnChange fires after a change has been made to anedit box. So this scheme works because the change has already been made andyou can readily measure the text size.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes