Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jan 29, 2020 2:50 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Modify String Passed as a Parameter
PostPosted: Sat Mar 19, 2011 10:55 am 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
I am passing a string into a plugin function all works fine but I want to
change the data in the string that has been passed as a parameter.

Dim nIdx as Integer
Dim Name As String="Mr Tester"
Dim Rate As String="New"

nIdx=MyPlugIn.Tester(Name,Rate)


I have set the second parameter in my method declarations as REALstring
and the rb decs to

{(REALproc) Tester,REALnoImplementation,"tester(name as string,byref rate as String) as Integer",},


I then use in my plugin code

static int tester(REALstring name,REALstring rate);

with

rate=REALBuildString("1001",4);

I have checked the value in the plugin by calling the msgbox class with

void MsgBox( REALstring msg )
{
void (*REALMsgBox)( REALstring ) = (void (*)( REALstring ))REALLoadGlobalMethod( NULL, "MsgBox( s as String )" );
if (REALMsgBox) {
REALMsgBox( msg );
}
}

The string is 1001 in the plugin but the change is not reflected in the RB variable when it returns

Should I lock the string, copy it to the target (Rate) and then return

I just know there is a simple answer to this one can some on switch on the light for me lol

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Modify String Passed as a Parameter (Solved)
PostPosted: Mon Mar 21, 2011 4:37 am 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
What a trip, this weekend I took the time and effort to rip the documentation apart
and test every call / feature. I have solved my issue of modifying a variable passed byref it was garbage code
in my method. and read and digest every post in this area.

There are some great questions and answers here and I urge people to read them all play with the problems
and see how they are solved.

I also managed to get my head around memory blocks and getting a plugin to build the memory block set its values
and return is to RealBasic.

Now I can use

Dim TargetMb As MemoryBlock
Dim mPlugin As New MyPlugin
Dim InBoundPacket As String

InBoundPacket=Chr(&h23)+chr(&h101)+Chr(&h23)+chr(&h101)Chr(&h23)+chr(&h101)Chr(&h23)+chr(&h101)Chr(&h23)+chr(&h101)

TargetMb=mPlugin.decodePacket(inboundPacket)

My TargetMb on return is populated with the correct data and is the size what I specified in the plugin.

Its all about pointers what is what christian from MBS points out, if you need to master one thing in 'C' and 'C++' its pointers.
make them your friend this will save you hours of frustration.

One thing that I did see the light with was write classes not procedural code in a plugin, its much easier and cleaner to do so and you
have the advantage of course of using all the features of classes in native RB.

I have to say that the API once you take the time and effort not only to ask daft questions but also read the documentation
print the samples out and play with them, break them and then fix them is the only way for us mortals to master the black art
of plugin programming.

Thanks to all the guys that have replied to my questions you have been a great help to me and my quest to master the API.

What a fantastic system RB is, well done to all at Real Software (they know how good it is anyway ) and all the authors on this forum this is a great resource.

Again sorry for the barmy questions guy's but if you do not ask you wont learn ...

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Modify String Passed as a Parameter
PostPosted: Tue Mar 22, 2011 12:38 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
mark.gregory wrote:
static int tester(REALstring name,REALstring rate);


that must be

static int tester(REALstring name,REALstring &rate);

note the & for byref in C?

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group