Page 1 of 1

Posted: 10 Jul 2013, 23:31
by oli_lab
Hi !
I'm trying to make a user module that will put a new appearing character at the end of a existing string
this is for my project of born again Minitel (sooo french).

I already made a script that works fine, and was quite straight forward to make :

Code: Select all

//////////////////////////
// retourneur de string
/////////////////////////

// parameters declaration
Var input, dummy, reset   : TParameter;
Var output    : TParameter;
var sl1       : UNICODESTRING;
var sl2       : UNICODESTRING;
var size      : integer;

// destroy
procedure Destroy;
begin  
 sl1.free;
 sl2.free;
end;
// initialisation : create parameters
procedure init;
begin  
 SetModuleColor($800080+302999);
 input := createParam('in',ptTextField);
 SetIsOutPut(input,false);
 reset:=  CreateParam('reset',PtButton);  
 SetIsOutput(reset,false);
 output  := createParam('out',ptTextField);
 SetIsInPut(output,false);
 size  := createParam('size',ptDataField);
 SetIsInPut(size,false);
end;



// Global variables

//////////////////////////////
// CallBack proc
//////////////////////////////
Procedure CallBack(n:integer);
begin
if (n = reset) then begin
 IF (reset >= 1) THEN
  sl2 := getStringValue(input);
end;
if (n = input) then begin
 sl1 := getStringValue(input);
 sl2 := sl2 + sl1
 end;
 SetStringValue(output,sl2);
 SetValue(size,Length(sl2));
end;
Now I'm stuck with the user module : the sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) str); is the problem as every thing compile fine without it

Code: Select all

void StringFlip::onCallBack(UsineMessage *Message) 
{
	if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "enable" input
	{
	    m_textNew = sdkGetEvtPChar(m_textInput); //
		std::string str;
		str.push_back((char)m_textNew);
		sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) str); // this is not working, no conversion between std::string and AinsiCharPtr
	}

	if ((Message->wParam == 2) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "reset" input
	{
		sdkSetEvtPChar(m_textOutput, "");
	}
}
I did some research on the old 5.8 archive and find this :
http://www.sensomusic.com/wiki/doku.php?id=sdk:code:snippets:event_parameters:

but I don't understand "what" is pPrototype->PTextTest->len; I need to declare it but how ?

well I'm stuck !

thanx for your help.

Posted: 11 Jul 2013, 08:31
by bsork
I too have a similar problem, but I was trying to use a std::string variable as a parameter caption. I tried different approaches, and ended up with casting similar to examples in the SDK:

(AinsiCharPtr) (s.c_str())

This compiled without warnings, and the string also looked OK when traced, but the parameter caption was empty.

Posted: 11 Jul 2013, 11:29
by martignasse
oli_lab wrote:I'm trying to make a user module that will put a new appearing character at the end of a existing string
bsork wrote:I too have a similar problem, but I was trying to use a std::string variable as a parameter caption. I tried different approaches, and ended up with casting similar to examples in the SDK:

(AinsiCharPtr) (s.c_str())

This compiled without warnings, and the string also looked OK when traced, but the parameter caption was empty.
using std::string and casting it like that is the way to go.

but be sure to declare this std::string variable at module level (in the include file, as a member of the module), you can modify it's content at any time, but declaring it as a member variable of the module ensure the variable is alive when usine try to copy it's content.

if you declare it in the onGetParamInfos() or onCallback() function, it's just a locale variable without enough lifetime and is already destroyed when usine try to copy it's content.

to resume :
declare the string variable as a module member.
construct or modify the string content when you want before using it

Posted: 11 Jul 2013, 12:13
by bsork
I thought it might have something to do with scope, but it got to late last night to try that approach. However, it seems a bit strange as long as I build the string locally and immediately assign the value to the Caption member. One would think that the value is stored in Caption together with all the other data, and that the (temporary) string variable no longer is of interest.

Well, anyway, I'll try with a global variable tonight.

Posted: 11 Jul 2013, 12:34
by martignasse
bsork wrote:However, it seems a bit strange as long as I build the string locally and immediately assign the value to the Caption member. One would think that the value is stored in Caption together with all the other data, and that the (temporary) string variable no longer is of interest.
but the variable stored in Caption is a pointer, who is just the address to the string content
so the string have to be alive until this pointer is used by usine to access the string content and copy it

welcome in C/C++ world ;)

Posted: 11 Jul 2013, 14:32
by bsork
martignasse wrote:welcome in C/C++ world ;)
...and thank you! :)

Of course, a pointer - I didn't think of that. That's why you go to all the trouble with vector arrays and all in the matrix modules.

Posted: 11 Jul 2013, 17:42
by oli_lab
oh well, I'm going nowhere.

is "declare the string variable as a module member." means here :
protected:
// protected members goes here ?

...

Code: Select all

                m_textNew = sdkGetEvtPChar(m_textInput); //
		str.push_back((char) m_textNew);
		sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) (str.c_str()));
		//sdkSetEvtPChar(m_textOutput, m_textNew);
there's something wrong with the cast as if I set 77 on the input I get 'P' on the output.

Posted: 11 Jul 2013, 20:54
by martignasse

Code: Select all

         m_textNew = sdkGetEvtPChar(m_textInput); //
        str.push_back((char) m_textNew);
        sdkSetEvtPChar(m_textOutput, (AinsiCharPtr) (str.c_str()));
        //sdkSetEvtPChar(m_textOutput, m_textNew);
m_textNew is a char pointer, and you add it to str as a char, that's the problem

replace

Code: Select all

 str.push_back((char) m_textNew);
by

Code: Select all

str.append(m_textNew);
and it should work

Posted: 12 Jul 2013, 01:53
by oli_lab
yes it is working now ! Many thanks !

weird, this wasn't working :

Code: Select all

if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE) && (Message->result == 1)) //received 1 on "enable" input
    {
but this is working fine

Code: Select all

	if ((Message->wParam == 1) && (Message->lParam == MSG_CHANGE)) 
	        {
		  if (sdkGetEvtData(m_enable) == 1)
		{
so now I have the proper user module to write text from a MINITEL to Usine, next to do is the module to send comma text to the MINITEL

And in between I have to better understand C++ syntax, hope "le site du zero" will suffice.

Posted: 05 Apr 2015, 02:58
by Blaakk
I know this is from relatively back-in-the-day but I just ran into the same compiler fail. Y'all probably will kick yourselves.

AinsiCharPtr
^
AnsiCharPtr

6.2 is superb.

Posted: 13 Apr 2015, 09:43
by martignasse
Blaakk wrote:I know this is from relatively back-in-the-day but I just ran into the same compiler fail. Y'all probably will kick yourselves.

AinsiCharPtr
^
AnsiCharPtr

6.2 is superb.
hi Blaakk,

Yep, i made some refactoring with this version.
It's mentioned in the 'Release notes' which should be consulted carefully for each version release.
We try to avoid refactoring as it can prevent existing code to compile, but in some case, we have to.

The gold rule is to always read the 'Release notes' for new distrib version.

I'm really happy that you like the 6.2 :D