Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text input that drives data results sample ?

Status
Not open for further replies.

CliffClimber

Technical User
Sep 18, 2003
16
US
Having trouble getting user input text connected in a way to bring up matches from dbf table. Been using (trying) Delphi 7 for 1 week. Trying to do this with DataSource and DataComboBox with the one table on the client machine. Does anyone have a (simple) example they could show me. I am not familiar with the code yet and have been trying to do this using the Object Inspector.
Thanks !
Cliff
 
Is this what you are looking for :

table1.FindNearest([trim(EditSearch.Text)]);

or

table1.FindKey([trim(EditSearch.Text)]);

Hope this help.
 
Karen,
Very new at this ... What you sent may work but where do I put it? The book is not clear concerning this. The following is from Unit1.pas. I would prefer to learn this to using the Object Inspector if possible.
Thanks for your response!


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, StdCtrls, DB, DBTables, Mask, Grids, DBGrids;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBComboBox1: TDBComboBox;
DBComboBox2: TDBComboBox;
DBComboBox3: TDBComboBox;
DBComboBox4: TDBComboBox;
DBNavigator1: TDBNavigator;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
 
Let's assume that your DBF table has two fields. An integer key field called KEY and a character field called NAME.

The sample code that follows will allow the user to enter a number in an edit field and then click on a button to reveal the name associated with the key. I'm sure your application will be more complex but the ideas should apply.

Put the following components on your form:

TTable - name it mensa
TDataSource - name it sauce
TDBEdit - name it dbeName
TEdit - name it edKey
TButton - name it btnFind

Ensure that there is a database alias set up for your table (use BDEAdmin.EXE).
Set the Text property of edKey to blank
Set the DatabaseName property of mensa to the alias name Set the TableName property of mensa to the actual .DBF name of the table
Set the Active property of mensa to True
Set the DataSet property of sauce to mensa
Set the DataSource property of dbeName to sauce
Set the DataField property of dbeName to NAME
At this point the actual NAME data from the first record of the table should be visible in dbeName.

Now double click on the button. An edit window should appear into which you should add code so it looks like this:
Code:
procedure TForm1.btnFindClick(Sender: TObject);
begin
  if not mensa.FindKey ( [ StrToIntDef ( edKey.text, Low(integer) ) ] ) then
    ShowMessage ( 'No record for this key' );
end;

If you are not sure what things like FindKey and StrToIntDef to check out the Delphi Help by pressing F1.

Now (save and) run (F9) the program.

There's quite a lot to learn when you first use Delphi. But it is a really neat, powerful development tool and well worth the effort. There are a lot of Delphi enthusiasts in this forum who will be pleased to help you but remember to have a go first and demonstrate that you've tried. Ideally show a bit of code and say "I'm trying to get this effect with this bit of code but it fails in this way" rather than simply "Show me how to do this".

Andrew
 
Andrew,
Thank you for your example and suggestions.
I have picked up a few points concerning design from your well expressed example.
Thanks!




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top