关键:Find要事先Sort排序,Indexof不用排序. TStringList内部查找相关的数据.待调试代码时才知道痛苦,浪费无数时间后,只得一步步跟踪,才发 现Find方法返回的Index总是错误的,当时一阵郁闷,随手按下F1键,Find的Help文档展现眼前,对于该 函数是这样描述的:Locates the index for a string in a sorted list and indicates whether a string with that value already
取消自动创建窗体 Form1关键代码 implementation uses Unit2; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if not Assigned(Form2) then //assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(false). begin Form2 := TForm2.Create(Self); Form2.Show; en
var IsHave:Boolean; begin adoquery.first; while(not adoquery.eof) do begin if(adoquery.fieldbyname('列名').asstring="用户添加的值") then begin IsHave=True; break; end; adoquery.next; end; if(IsHave)then showmessage("存在重复数据!"); end;
今天看了多年前的一个帖子,发现回答不合理,有些还将其归为delphi的bug.其实主要是没有灵活应用参数. ADOQUERY查询时,这样不行,结果不正确. WITH ADOQUERY1 DO BEGIN CLOSE;SQL.CLEAR; SQL.ADD('SELECT * FROM TABLE1 WHERE TA001=:MONTH AND TA002=:MONTH'); PARAMETERS.ParamByName('MONTH').Value :=EDIT1.TEXT; OP