Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code looks like this.


Delphi
procedure TForm1.BtnSearchClick(Sender: TObject); 
var 
sStudent :String; 
begin 
sStudent:=EdtSearch.Text; 
RDisp.Lines.LoadFromFile('Students\ ' +sStudent+ '.txt'); 
if sStudent<>' ' 
then 
begin 
Application.MessageBox('No data has been inputed. Please Input a name to search','Error no information to search',0); 
end; 
end; 


basically what I need is the sStudent(which is a Tedit) to search for a student name, If the Tedit is empty it should show an error ("No data has been inputed. Please Input a name to search") etcetera, what I get is the messagebox even though the rich edit has pulled up the information

What I have tried:

I have tried everything, but even though we had extensive classes on this I still cant find it... chances are its right under my nose and I too blind to see it.
Posted
Updated 4-Aug-16 10:56am

1 solution

I haven't touched Delphi in years, but I'd assume that if sStudent <> ' ' will execute everything inside the if block unless the textbox contains a single space. So if you leave it empty, or type in anything other than a single space, the message will be shown.

You probably also want to move the LoadFromFile line into an else block, and you might need to remove the leading space from the file name, depending on how you've named the files.
Delphi
sStudent := EdtSearch.Text; 

if sStudent = '' 
then 
begin 
    Application.MessageBox('No data has been inputed. Please Input a name to search', 'Error no information to search', 0); 
end
else
begin
    RDisp.Lines.LoadFromFile('Students\' + sStudent + '.txt'); 
end; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900