Solved

DB Grid "AutoFill" Please Help

Posted on 1997-10-25
4
182 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
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 150 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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