Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DB Grid "AutoFill" Please Help

Posted on 1997-10-25
4
Medium Priority
?
213 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

604 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