| | |
Help with delphi project
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
I have recently made a program that stores peoples names, address, etc in a text file. On one of the forms, I want there to be a search option, so the user can search by name and then the persons address is displayed. Like a search engine in a database. I have spent hours trying to work out what the code is for the search button, but its killing me, I can't work it out.
Could someone please help me out with the code.
Regards Satrix
Could someone please help me out with the code.
Regards Satrix
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
For a start, delphi, assigns the record to the file, then opens the file for reading to. Then it resets it, then writes to the file and then closes it.
What I'm really asking help for is:
The file has three names in it and each name has an address assigned to it.
e.g.
Scott 32 Roy Close
Katie 31 Roy Close
Chris 2 Roy Close
I type in a name like katie. It then searches the file for the name and then displaies the address that is assosiated to that name.
Is that clearer?
What I'm really asking help for is:
The file has three names in it and each name has an address assigned to it.
e.g.
Scott 32 Roy Close
Katie 31 Roy Close
Chris 2 Roy Close
I type in a name like katie. It then searches the file for the name and then displaies the address that is assosiated to that name.
Is that clearer?
•
•
Join Date: Aug 2005
Posts: 6
Reputation:
Solved Threads: 0
procedure TForm1.Button1Click(Sender: TObject);
var line,name,adress:string;
___f:textfile;
begin
_____assignfile(f,'filename');reset(f);
_____adress:='';
_____repeat
_________readln(f,line);
_________name:=copy(line,1,pos(' ',line)-1);
_________adress:=copy(line,pos(' ',line)+1,length(line));
_____until (lowercase(name)=lowercase(edit1.Text)) or (eof(f));
_____if adress='' then adress:='no name found';
_____edit2.Text:=adress;
_____closefile(f);
end;
my procedure reads the name from edit1 and returns the adress to edit2. replace 'filename' with the name of the file u have
var line,name,adress:string;
___f:textfile;
begin
_____assignfile(f,'filename');reset(f);
_____adress:='';
_____repeat
_________readln(f,line);
_________name:=copy(line,1,pos(' ',line)-1);
_________adress:=copy(line,pos(' ',line)+1,length(line));
_____until (lowercase(name)=lowercase(edit1.Text)) or (eof(f));
_____if adress='' then adress:='no name found';
_____edit2.Text:=adress;
_____closefile(f);
end;
my procedure reads the name from edit1 and returns the adress to edit2. replace 'filename' with the name of the file u have
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
The code that you gave me works in the sence of it displays the address but, only displays the letters in the address not the number, and also you can type in any name and it will display the address. E.g.
The names in the list:
Katie
Andy
Elaine
Scott
You could type in Chris and it will still display one of the address. What ever name you type in it will display the last address that you have entered into the file.
I have tryed to change it but have got stuck. Could you please help me again.
If it helps hears the code for the form:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
details=record
name:string[30];
address:string[50];
end;
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
Button2: TButton;
Button3: TButton;
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
detailsrecord:details;
detailsfile:file of details;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject);
begin
form1.detailsrecord.name:=edit1.text;
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
form1.detailsrecord.address:=edit2.text;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with form1 do
begin
assignfile(detailsfile,'details.txt');
reset(detailsfile);
seek(detailsfile,filesize(detailsfile));
write(detailsfile,detailsrecord);
closefile(detailsfile);
end;
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.Button2Click(Sender: TObject);
var line,name,address:string;
f:textfile;
begin
assignfile(f,'details.txt');reset(f);
address:='';
repeat
readln(f,line);
name:=copy(line,1,pos(' ',line)-1);
address:=copy(line,pos(' ',line)+1,length(line));
until (lowercase(name)=lowercase(edit3.Text)) or (eof(f));
if address='' then address:='no name found';
edit4.Text:=address;
closefile(f);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit3.Text:='';
edit4.Text:='';
end;
end.
The names in the list:
Katie
Andy
Elaine
Scott
You could type in Chris and it will still display one of the address. What ever name you type in it will display the last address that you have entered into the file.
I have tryed to change it but have got stuck. Could you please help me again.
If it helps hears the code for the form:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
details=record
name:string[30];
address:string[50];
end;
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
Button2: TButton;
Button3: TButton;
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
detailsrecord:details;
detailsfile:file of details;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject);
begin
form1.detailsrecord.name:=edit1.text;
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
form1.detailsrecord.address:=edit2.text;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with form1 do
begin
assignfile(detailsfile,'details.txt');
reset(detailsfile);
seek(detailsfile,filesize(detailsfile));
write(detailsfile,detailsrecord);
closefile(detailsfile);
end;
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.Button2Click(Sender: TObject);
var line,name,address:string;
f:textfile;
begin
assignfile(f,'details.txt');reset(f);
address:='';
repeat
readln(f,line);
name:=copy(line,1,pos(' ',line)-1);
address:=copy(line,pos(' ',line)+1,length(line));
until (lowercase(name)=lowercase(edit3.Text)) or (eof(f));
if address='' then address:='no name found';
edit4.Text:=address;
closefile(f);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit3.Text:='';
edit4.Text:='';
end;
end.
•
•
Join Date: Aug 2005
Posts: 6
Reputation:
Solved Threads: 0
procedure TForm1.Button1Click(Sender: TObject);
var f:textfile;
name,adress:string;
c:char;
begin
assignfile(f,'c:\details.txt');reset(f);
while not eof(f) do
begin
name:='';
read(f,c);
while c<>' ' do
begin
name:=name+c;
read(f,c);
end;
if lowercase(name)=lowercase(edit1.Text) then
begin
readln(f,adress);
edit2.Text:=adress;
exit;
end else readln(f);
end;
edit2.Text:='name not found';
closefile(f);
end;
this one i actulay tested
it works good:writes corect adress and display 'name not found' if the name is not in the file. and its the best optimize i could get
... or maybe i shouldnt read all the name if the first letters don't match
var f:textfile;
name,adress:string;
c:char;
begin
assignfile(f,'c:\details.txt');reset(f);
while not eof(f) do
begin
name:='';
read(f,c);
while c<>' ' do
begin
name:=name+c;
read(f,c);
end;
if lowercase(name)=lowercase(edit1.Text) then
begin
readln(f,adress);
edit2.Text:=adress;
exit;
end else readln(f);
end;
edit2.Text:='name not found';
closefile(f);
end;
this one i actulay tested
it works good:writes corect adress and display 'name not found' if the name is not in the file. and its the best optimize i could get
... or maybe i shouldnt read all the name if the first letters don't match
•
•
Join Date: Jul 2005
Posts: 18
Reputation:
Solved Threads: 0
What you need is radiogroupname.itemindex, the item index starts from 0 to refer to a particular radio component. So you can use an if statement on a button click or whatever. This will give you
if radiogroupname.itemindex=0 then
begin
//do song 1 stuff//
end
else if radiogroupname.itemindex=1 then...
and so on.
Hope this helps
if radiogroupname.itemindex=0 then
begin
//do song 1 stuff//
end
else if radiogroupname.itemindex=1 then...
and so on.
Hope this helps
![]() |
Similar Threads
- New to Pascal and need to open project. (Pascal and Delphi)
- Right aligning items in TListBox (C++ Builder) (C++)
Other Threads in the Pascal and Delphi Forum
Views: 4148 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





