DynamicString.concatf,concatx

General help with the eC language.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

DynamicString.concatf,concatx

Post by samsam598 »

Given below code,MessageBox.contents wants to fetch all lines input from editBox1 and a "\n" to separate them line by line.DynamicString.concat(String) works as expected,but for concatf and concatx,maybe I was totall wrong.I just want to concat all inputs into DynamicString buffer.My attempt failed anyway.Help would be appreicated.

PS:don't know why first "\n" in editBox2.AddS shows correct ,but all the rest "\n" show as "|.n" here in the post.

Code: Select all

 
import "ecere"
import "DynamicString"
static DynamicString buffer{};
class Form1 : Window
{
   caption = "Form1";
   background = formColor;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 440, 204 };
   anchor = { horz = -31, vert = -68 };
 
   DynamicString str{};
   Button button1 
   {      
      this, caption = "Get", altG, isDefault = true, size = { 90, 29 }, anchor = { left = 48, bottom = 19 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         //char howmany[1024];
         //buffer=DynamicString{};
         str=editBox1.contents;
         //String str=editBox1.contents;
         editBox2.AddS(str);
 
         editBox2.AddS("\n");
         //buffer.concat(str);
         //buffer.concatf("%s\n",str);
         //buffer.concatx(str,"",str,"\n");
         //buffer.concatx(buffer,str,"\n");
         buffer.concatf("%s",str," ",str);
         editBox2.SetViewToCursor(true);
         Update(null);
         //this.Update(0);
         //delete str;
         MessageBox{contents=buffer}.Modal();//CopyString(buffer);
         return true;
      }
   };
   Button button2 
   {
      this, caption = "Exit", escape, size = { 82, 29 }, anchor = { right = 38, bottom = 19 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Destroy(0);
         return true;
      }
   }
   EditBox editBox1 { this, caption = "editBox1", size = { 382, 19 }, anchor = { left = 24, top = 16, right = 26 } };
   EditBox editBox2 { this, caption = "editBox2", anchor = { left = 24, top = 56, right = 26, bottom = 61 }, hasVertScroll = true, multiLine = true }
 
   bool OnPostCreate(void)
   {
      editBox1.Activate();
      return true;
   };;
}
 
Form1 form1 {};
 
 
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: DynamicString.concatf,concatx

Post by jerome »

Hi Sam,

DynamicString::concatf works like printf so I assume that instead of:

buffer.concatf("%s",str," ",str);

You meant:

buffer.concatf("%s %s",str, str);

To add the string twice with a space in between.

The other problem here is that you're giving concatf a DynamicString object but %s format specifier expects a char * (or String which is equivalent right now).

buffer.concatf("%s %s",(String)str, (String)str);

This will ensure the proper conversion properties are invoked.

For concatx, buffer.concatx(str, " ", str); this should work, except that DynamicString is missing stringification methods so it shows up with a bunch of commas instead (The default Array behavior that DynamicString inherits from)

If you add to the DynamicString class:

Code: Select all

char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
   return array;
}
 
bool OnGetDataFromString(char * string)
{
   this = (DynamicString)string;
}
That should solve that issue.

Regards,

-Jerome
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: DynamicString.concatf,concatx

Post by samsam598 »

Thanks.Yes,perfect.
Post Reply