I got a edit and a listbox on my canvas, the listbox content is loaded with the content of an txt file, In order to do that I used the code:
listbox1.Items.LoadFromFile('data\data.dat');
When typing the name on edit I want to highlight it on the listbox, so I used the code:
procedure TformMain.Edit1Change(Sender: TObject);
const
indexStart = -1;
var
search : array[0..128] of Char;
begin
StrPCopy(search, Edit1.Text) ;
ListBox1.ItemIndex := ListBox1.Perform(LB_SELECTSTRING, indexStart, LongInt(@search));
end;
Now with a button on my canvas I want to delete the selected name from the txt.
How can I do that?
Thanks in advance!
If you just want to delete the text that matches the edit control:
var
newS : string;
...
newS := ListBox1.Items[ListBox1.ItemIndex];
Delete(newS,Pos(Edit1.Text,newS),Length(Edit1.Text));
ListBox1.Items[ListBox1.ItemIndex] := newS;
If you want to remove the whole line:
ListBox1.Items.Delete(ListBox1.ItemIndex);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.