大家好,我有关于delphi编程的请求,不要告诉我它已经过时,因为我知道,这是一个学校项目? [英] Hi everyone I have a request about delphi programming, dont tell me its obsolete because I know, this is a school project?

查看:80
本文介绍了大家好,我有关于delphi编程的请求,不要告诉我它已经过时,因为我知道,这是一个学校项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码看起来像这样。





程序TForm1.BtnSearchClick(发件人:TObject) ; 
var
sStudent: String ;
开始
sStudent:= EdtSearch。 Text ;
RDisp.Lines.LoadFromFile(' 学生\' + sStudent + ' .txt');
如果 sStudent<> ' '
然后
开始
Application.MessageBox(< span class =code-string>' 没有数据被输入。请输入一个名称来搜索'' 错误没有搜索信息',0);
end ;
end ;





基本上我需要的是搜索学生姓名的sStudent(这是一个Tedit),如果Tedit为空它应该是显示错误(没有输入数据。请输入要搜索的名称)等等,即使丰富的编辑已经提取信息,我得到的是消息框



我尝试了什么:



我已经尝试了所有的东西,但即使我们有广泛的课程,我仍然无法找到它...机会在我的鼻子底下,我也无视它。

解决方案

多年来我没有接触过Delphi,但我认为如果sStudent<> 将执行中的所有内容,如果阻止,除非文本框包含单个空格。因此,如果您将其留空,或键入除单个空格以外的任何内容,则会显示该消息。



您可能还想移动 LoadFromFile 行到 else 块,您可能需要从文件名中删除前导空格,具体取决于您的命名方式文件。

 sStudent:= EdtSearch。 Text ; 

如果 sStudent = ' '
然后
开始
Application.MessageBox (' 未输入任何数据。请输入名称以搜索'' 错误没有搜索信息',0);
end
else
开始
RDisp.Lines.LoadFromFile(' Students\'+ sStudent +' .txt ' );
结束;


my code looks like this.


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.

解决方案

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.

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; 


这篇关于大家好,我有关于delphi编程的请求,不要告诉我它已经过时,因为我知道,这是一个学校项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆