send command and comma in parameter

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
TommiG
Posts: 8
Joined: Tue Dec 06, 2011 9:45 am

send command and comma in parameter

Post by TommiG » Tue Dec 06, 2011 10:22 am

Dear colleagues,
I am new in the LiveCode universe, please forgive me, but found a problem I don't know how to handle.

I wrote a simple command "LoadFromFile" which accepts a valid file name in an image control.
When I like to use it inside a Button onMouseup handler and have to call it outside of the normal message path, I learned to use the send command.
But curiously the send command accepts a string. Therefore we have to write:

send "LoadFromFile " & tFileName to image "foo"

But sometimes filenames contains commas and maybe other funny characters, e.g. "my,best,image.jpg" is a valid filename!
Now as my LoadFromFile command accepts only one parameter, it sees only the front part of the file name (in the previous sampe "my").
How do I prevent this?
Do I really have to send custom command names and their parameters as strings???
Do I have to escape special characters in strings which have a special meaning in the LiveCode language?

Thank you in advance,
Thomas

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: send command and comma in parameter

Post by Dixie » Tue Dec 06, 2011 10:38 am

Thomas...

You could do something like this... say, in the script of a button

Code: Select all

on mouseUp
   put "myStangelyFormatted, fileName.jpg" into theFile
   loadFromFile theFile
end mouseUp
then say in the card script...

Code: Select all

on loadFromFile theFile
   put theFile
end loadFromFile
and then in this example... myStangelyFormatted, fileName.jpg ... will be returned in the msg box.

Dixie

TommiG
Posts: 8
Joined: Tue Dec 06, 2011 9:45 am

Re: send command and comma in parameter

Post by TommiG » Tue Dec 06, 2011 10:56 am

Dear Dixie,
thank for you answer. But calling a command in the message path is not really a problem.
But my command is not in the message path. It is in another control.
Therefore I have to use "send".

In my button script

Code: Select all

on mouseUp
   put "myStangelyFormatted, fileName.jpg" into theFile
   send "loadFromFile " & theFile to image "myImg"
end mouseUp
In my image script

Code: Select all

on loadFromFile theFile
   put theFile
end loadFromFile
and here the message box shows only "myStangelyFormatted".
Do you have a solution for this?
Thank you in advance.
Regards, Thomas

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: send command and comma in parameter

Post by Dixie » Tue Dec 06, 2011 11:11 am

Thomas...

Have a look at the 'dispatch' command in the dictionary... I think that this will be your friend in this case.
A quick example... let's say in the script of a button on card 1

Code: Select all

on mouseUp
   put "boo" into tData
   dispatch "updateField" with tData
end mouseUp
and then in the card or stack script

Code: Select all

on updateField tdata
   put tdata into fld 1 of card 2
end updateField
any help...?

Dixie

TommiG
Posts: 8
Joined: Tue Dec 06, 2011 9:45 am

Re: send command and comma in parameter

Post by TommiG » Tue Dec 06, 2011 12:04 pm

Dear Dixie,

I tried

Code: Select all

on mouseUp
   put "myStangelyFormatted, fileName.jpg" into theFile
   dispatch "loadFromFile" to image "myImg" with theFile
end mouseUp
and this works now!!!
Thank you very much for your help.
Have a nice day.
Best regards,
Thomas

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: send command and comma in parameter

Post by FourthWorld » Tue Dec 06, 2011 4:21 pm

Extra bonus points: not only is the syntax for passing arguments with "dispatch" slightly simpler than with "send", but in terms of execution speed "dispatch" performs measurably faster (not enough to be noticeable, but if you need to use such things frequently it can add up).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply