Given below code,the EditBox1 load the source code in its PostCreate method,now I'm trying to seek some strings(key words) in the content of EditBox1,but found that the seeking is only workable for the first line of the contents.Any attempt to seek after the first line will return -1(not found).
Not sure whether I've missed anything important.Please help.Thanks.
Code: Select all
import "ecere"
class Form1 : Window
{
caption = "读取文件";
background = activeBorder;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 296, 316 };
anchor = { horz = -119, vert = -29 };
EditBox editBox1 { this, caption = "editBox1", anchor = { left = 8, top = 48, right = 10, bottom = 13 }, hasHorzScroll = true, true, readOnly = true, true };
bool OnPostCreate(void)
{
File file=FileOpen("form1.ec",read);
editBox1.Load(file);
delete(file);
return true;
}
Button button1
{
this, caption = "button1", position = { 192, 16 };
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
int idx;
char result[255];
char* str="class";
idx=find(editBox1.contents,str);
sprintf(result,"The word \"%s\" starts at index %d\n",str,idx);
MessageBox{type=ok,contents=result}.Modal();
return true;
}
};
int find(char* src,char* str)
{
char* result=strstr(src,str);
if(result==null) return -1;
return (int)(result-src);
}
}
Form1 form1 {};