Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"This is a delphi project that I need help with as in History of programming project" ok so it goes like this, I have my code fleshed out on the search system where basically if you search a blank Tedit it will give you an error, now I have hit a road block as I want it to produce a new error if the item searched doesnt exist... this is the code that is eating at me.
Delphi
procedure TForm1.BtnSearchClick(Sender: TObject);
var
sStudent :String;
begin
    sStudent:=CbSearch.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 + '.zip');
end;
end;


I know that below the "Rdisp.Lines" I need to provide another conditional if statement but I dont know how to go about it... Please help

What I have tried:

I have tried adding an if statement but I got rid of that as soon as it crashed my program... I know I need an "if sStudent='' "etc, but I dont have a clue what to do it on...
Posted
Updated 9-Aug-16 8:09am
Comments
[no name] 9-Aug-16 12:44pm    
Hard to figure out what the problem is, at least for me.
Do you like to check whether the files exists?
Is the problem LoadFromFile? What type is RDisp, that you can load a zip file to it?
Crytach Daiguren 9-Aug-16 12:53pm    
Ahhh yes... RDisp is a Richedit, basically what I want is, if you search "Mario" in the Tedit it will display an error message that says "Student doesnt exist", the way I have it is studnent data is stored in a protected zip file, and thats working perfectly, I just want the condition that if the Search word doesnt exist then I get an error.
[no name] 9-Aug-16 13:17pm    
I assume you like to search it i the RichEdit. If yes, have a look here in the acepted answer:
filter - Counting specific text in memo (Delphi) - Stack Overflow[^]. The example is for Memo but what I remember is, that RichText has also a property Lines.
Crytach Daiguren 9-Aug-16 13:48pm    
Nope lets see if I can put this properly... when a students data is saved it is saved to a "Students_name.zip" when I search that name "Students_Name" it brings up the data in a richedit (THAT IS ALL DONE ALREADY SO I DONT NEED HELP FOR THAT)... now what I want to do is condition that is "If student name does not exist then display error message 'student doesnt exist'" similar to the one you see above.
[no name] 9-Aug-16 14:04pm    
What does "If student name does not exist" exactly means? The file does not exists?
¿Qué significa "If student name does not exist" exactamente? No existe el archivo "....\Students_Name.zip"?

1 solution

It sounds like you're looking for the FileExists function[^]:
Delphi
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 if Not FileExists('Students\' + sStudent + '.zip')
then
begin
    Application.MessageBox('Student file not found.', 'Error file not found', 0);
end
else
begin
    RDisp.Lines.LoadFromFile('Students\' + sStudent + '.zip');
end;

However, it's not clear whether the LoadFromFile method[^] supports reading Zip files. I would expect it to only support text files.
 
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