Ecere SDK/eC Forums
http://ecere.org/community/
Print view

What's EditBox1.contents after EditBox1.Load(file1)?
http://ecere.org/community/viewtopic.php?f=5&t=231
Page 1 of 1
Author:  samsam598 [ Tue Apr 10, 2012 9:54 pm ]
Post subject:  What's EditBox1.contents after EditBox1.Load(file1)?

Greetings!

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 {};
 
 
Author:  jerome [ Tue Apr 10, 2012 10:37 pm ]
Post subject:  Re: What's EditBox1.contents after EditBox1.Load(file1)?

Hi Sam,

Due to memory allocation issues, 'contents' will only return the current line of the EditBox.

You can use the 'multiLineContents' property to return the whole contents, but every time you use that property the returned string needs to be freed (with the delete operator).

Regards,

Jerome
Author:  samsam598 [ Wed Apr 11, 2012 4:59 am ]
Post subject:  Re: What's EditBox1.contents after EditBox1.Load(file1)?

Hi Jerome,

Thanks for the help.It works perfect.

Just found that strlen("道") in eC is 3 instead of 2.Not tested in C whether the same.

Regards,
Sam
Author:  jerome [ Wed Apr 11, 2012 11:25 am ]
Post subject:  Re: What's EditBox1.contents after EditBox1.Load(file1)?

Hi Sam,

It's not a matter of the language, but rather the encoding.

UTF-8 is standard with Ecere. In UTF-8 all Chinese characters are at least 3 bytes.

http://en.wikipedia.org/wiki/UTF-8

In UTF-16 (the Windows Unicode encoding), they are 2 bytes.

UTF-8 is a much better encoding system, mainly because it is backward compatible with ASCII.
This way you do not need to duplicate APIs for ASCII strings and Unicode strings.

Regards,

Jerome
All times are UTC-05:00 Page 1 of 1