
procedure TForm1Edit1KeyPress(Sender: TObject; var Key: Char);
var
ss,str: String;
i,ct,ps: Integer;
begin
if Key = #13 then begin
ss := Edit1Text;
if ss <> '' then begin
ct := ListBox1ItemsCount;
if ct > 0 then begin
str := '';
i := 0;
repeat
ps := Pos(ss, ListBox1Items[i]);
if ps > 0 then begin
str := ListBox1Items[i];
str := Copy(str, Length(ss) + 2,
Length(str) - Length(ss) - 1);
end;
Inc(i);
until (i >=ct) or (str <> '');
end;
end;
end;
ShowMessage('Str = ' + str);
end;
很显然,你的第二个值o替换掉了第一个值然后才加入的。这样写就有可能有两个值:
if a+b=c then o=e+d;
listboxitemsadd(o);
if c+f=q then o=g+h;
listboxitemsadd(o);
利用ClipboardasText; 利用UNICODE格式解决非英文字符的乱码问题
procedure SetClipboardText(AStr: string);
var // SetBuffer(CF_TEXT, PChar(Value)^, Length(Value) + 1);
Data: THandle;
DataPtr: Pointer;
Size: Integer;
WStr: PWideChar;
begin
Size := Length(AStr) 4;
WStr := AllocMem(Size);
try
// convert to Unicode
StringToWideChar(AStr, WStr, Size);
OpenClipboard(0);
EmptyClipboard;
Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);
try
DataPtr := GlobalLock(Data);
try
Move(WStr^, DataPtr^, Size);
SetClipboardData(CF_UNICODETEXT, Data);
finally
GlobalUnlock(Data);
end;
except
GlobalFree(Data);
raise;
end;
finally
CloseClipboard;
FreeMem(WStr);
end;
end;
其实你还可以用id>
LISTBOX1 和LISTBOX2 有什么联系?
删除listbox 的数据 就是listbox的 Items 进行删除。
每一个Items 你可以看作是 一条数据(也就是看到的一行),
每个Items 都有一个下标, 0 开始。
如果要删除 你看到 listbox1的第二条数据,就是 listbox1 Items[1]Delete;
具体代码楼上已经写了,我就不重复了
ListBox1Items[0], 取listbox 第一行的值,
copy(A,B,C) 是 取字符串A中 从B开始长度 为C 的子字符
length() 取 字符的长度
listboxitemindex 是你选中的选项 在listbox 中的位置。。。
OK,这个问题很清晰,主要在设计上面的理解问题!
那么问题的关键就在 dlgopen1FileName
这个 dlgopen1FileName 其实格式是:路径/文件名后缀
那么在设计的时候,就可以这样制作:
实例化一个 TStringList 用与保存 dlgopen1FileName
并将所保存到 TStringList 中对应的index 用来写入到 listboxAddItem('文件名',index);
这样,当listbox *** 作的时候,就可以根据 *** 作相的OBJ来在TStringList中索引到 文件的路径了
-------------------------华丽的分割线---------------------
上面这些是设计思路,下面提供一个参考代码:
-----------定义容器
private //在窗口类的私有字段中定义
{ Private declarations }
var FileNameList:TStringList=nil; //这个定义要在单元定义,不能在局部定义
-----------在窗口创建时实例化
FileNameList := TStringListCreate;
-----------添加部分//procedure TForm1btn1Click(Sender: TObject);
if dlgOpen1Execute then
begin
if FileNameListIndexOf(dlgopen1FileName) >= 0 then begin
ShowMessage('已在列表中!');
exit;
end;Add
lst1AddItem(ExtractFileName(dlgopen1FileName),
TObject(FileNameListAdd(dlgopen1FileName)));
end;
---------索引部分//procedure TForm1lst1Click(Sender: TObject);
if lst1ItemIndex >= 0 then
wp1url:=FileNameList[Integer(lst1ItemsObjects[lst1ItemIndex])];
-----------------华丽的分割线---------------
参考代码就到这里吧,你看这些手工码字不容易!
注意了,楼上的方法会增加系统的开销,并非理想办法!!!
如果我的回答帮助到你了,记得采纳答案,也点下赞同
吧! 还有什么疑问也可以继续找我!
以上就是关于delphi 中 在listbox中查找edit中的内容全部的内容,包括:delphi 中 在listbox中查找edit中的内容、delphi listbox用法、DELPHI 如何提取网页事件中的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)