Solved

DB Grid "AutoFill" Please Help

Posted on 1997-10-25
4
202 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

718 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