?
Solved

DB Grid "AutoFill" Please Help

Posted on 1997-10-25
4
Medium Priority
?
205 Views
Last Modified: 2010-04-04
I am writing a database program for my final year project and I'm stuck with this problem, could somebody assist me.

I would like to enter a two character airline code into one field and have the corresponding airline field automatically fill with the correct airline name, for example when the user types AF in the airline code DBEdit box the program autofills the airline DBEdit box with the airline name AIR FRANCE and then tabs onto the next entry field.

I would be greatful if someone could offer assistance.

Regards
0
Comment
Question by:tam97
[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
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 600 total points
ID: 1348889
I think the right approach is a code like this:

procedure TForm1.DBEdit1Change(Sender: TObject);
begin
With Sender as TDBEdit do begin
if Length(Text) = 2 Then begin
  DBEdit1.Text := AirLineName(Text);
  //AirLineName is the procedure that returns the airline name
  ActiveControl := TWinControl(Components[ComponentIndex + 1]);
end;
If there are any doubts, place a comment before rejecting the answer.

IHTH
0
 

Author Comment

by:tam97
ID: 1348890
Hi Itamar,
Thanks for such a speedy reply, this is my first time using the service,very impressed !

I am very much a beginner with Delphi would it be possible for you to explain your answer in a bit more "beginners detail" sorry for being a pain.

It may help if I explain the database is using Paradox tables constructed using the Desktop database tool that comes with Delphi 3, the airline table has two fields 1/ Airline Code 2/Airline Name. This table is linked with one other to the main table which contains the rest of the data.

Thanks again for your reply

Regards
0
 
LVL 4

Expert Comment

by:itamar
ID: 1348891
I think i can make things more simple.
Here is a sample working code with comments.
I supose you're using TTable components to manage your tables, so i did my sample on it.
I don't know your reasons, but consider using a BDLookUpComboBox instead, because it's a "clean" solution.
Feel free to place comments if you still have some doubts regardind to THIS question.

The code:

unit Unit2;

interface

uses
      SysUtils, Windows, Messages, Classes, Graphics, Controls,
      StdCtrls, Forms, DBCtrls, DB, DBTables, Mask, ExtCtrls,
      Dialogs, Buttons;

type
      TForm2 = class(TForm)
        Table1RegistrationNumber: TFloatField;
        Table1AirLineCode: TStringField;
        Table1Flight: TFloatField;
        Table1Hour: TTimeField;
        DBNavigator: TDBNavigator;
        Panel1: TPanel;
        DataSource1: TDataSource;
        Table1: TTable;
    Table2: TTable;
        Table2AirLineCode: TStringField;
    Table2AirLineName: TStringField;
        Table1AirLineName: TStringField;
    Label1: TLabel;
    EditRegistrationNumber: TDBEdit;
        Label2: TLabel;
    EditAirLineCode: TDBEdit;
    EditAirLineName: TDBEdit;
        Label3: TLabel;
    EditFlight: TDBEdit;
    Label4: TLabel;
        EditHour: TDBEdit;
    procedure FormCreate(Sender: TObject);
        procedure EditAirLineCodeChange(Sender: TObject);
        function AirLineName(Code: String): string;
      private
        { private declarations }
      public
        { public declarations }
      end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

function TForm2.AirLineName(Code: string): string;
begin
      Table2.IndexName := ''; //Sets the index to the primary key
      if not Table2.FindKey([Code]) Then begin
            ShowMessage('Air Line not found !'); //Dialogs unit in uses clause
            Result := '';
            Exit;
      end;
            Result := Table2['AirLineName'];
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
      Table1.Open;
      Table2.Open; //Opens the AirLine Table
end;

procedure TForm2.EditAirLineCodeChange(Sender: TObject);
begin
      With Sender as TDBEdit do
      if Length(Text) = Field.Size Then begin //Field size is more generic, so you can change the size of the field tomorrow
            EditAirLineName.Text := AirLineName(Text);
            //AirLineName is the function that returns the airline name
            if EditAirLineName.Text <> '' Then
                  EditFlight.SetFocus; //Replace EditFlight with the name of your next field in the form
      end;
end;

end.
0
 

Author Comment

by:tam97
ID: 1348892
Hi itamar

Thanks once again for your time and coming down to my level, I understand this answer much better and intend to implement it into my program for college with acknowledgements to yourself.

I look forward to using the service again and you never know you might be able to help again, in fact I know I'll be using the service again !.

Thanks again
tam97
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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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