What's EditBox1.contents after EditBox1.Load(file1)?

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

What's EditBox1.contents after EditBox1.Load(file1)?

Post by samsam598 »

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 {};
 
 
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: What's EditBox1.contents after EditBox1.Load(file1)?

Post by jerome »

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
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: What's EditBox1.contents after EditBox1.Load(file1)?

Post by samsam598 »

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
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: What's EditBox1.contents after EditBox1.Load(file1)?

Post by jerome »

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
Post Reply