ultrus Posted January 24, 2007 Share Posted January 24, 2007 Howdy,I'm attempting to convert a delphi script into the php equivelent as I'm using php to communicate with an external server. I don't know much about delphi, but it seems that arguments in a called function are actually returning values like this:[code]ServerObject.GetSettings('speed', current, default, min, max);[/code]'speed' is what is passed in, and the remaining arguments return something like this:[code]ShowMessage(Format('Current: %d, Defaut: %d, Min: %d, Max: %d', [current, default, min, max]))[/code]Can I do something like this in php? I have tried the following without success:[code]$settingsSpeed = $serverObject->GetSettings("speed", $current, $default, $min, $max);echo($min);[/code]Any ideas on this? Thanks much. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 [s]If you're asking how to define the default for an argument, it'sfunction foo($bar="x"){}If not, please rephrase the question, I don't get it.[/s]Okay I think I get it now, but I don't know how to do what you want without seeing more of your code. What is the serverobject class? Is speed a var of it? In your getsettings function, you'd have to handle getting the attributes. Quote Link to comment Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 Format() looks similar to printf. Is this all you need? Quote Link to comment Share on other sites More sharing options...
ultrus Posted January 24, 2007 Author Share Posted January 24, 2007 [s]nah. I found that as well. When the function is called, the server is supposed to return the $current, $default, $min, $max values of "speed" or whatever other string passed in. In php I'm used to just retirning one value from a function, but this function returns variables to the variable names you specify as arguments. $current, $default, $min, and $max are null before the function is used. Please excuse my lack of technical terms.[/s]printf($settingsSpeed) and Format($settingsSpeed) don't cause any errors, but still draw a blank. This is the only challenge I have. I'm able to make use of all other server functions from php. Thanks for the assist. :) Quote Link to comment Share on other sites More sharing options...
ultrus Posted January 24, 2007 Author Share Posted January 24, 2007 GetSettings() is out of my control. I'm just trying to make use of it from my end of things. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 $settingsSpeed = $serverObject->GetSettings("speed", $current, $default, $min, $max);echo($min);What does this code do? Do you know what GetSettings does? Are those even valid arguments?I thought you said you were converting it - if you're writing it, can't you change what GetSettings does?PHP passes by value - try passing those by reference? &$minOtherwise $min is not affected by the function, because the $min in the function is a copy of $min. (confused yet?) Quote Link to comment Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 I'm not clear on what you want. Something like this perhaps?[code]<pre><?php function test ($something, $current, $default, $min, $max) { printf('Current: %d, Defaut: %d, Min: %d, Max: %d', $current, $default, $min, $max); } test('speed', 1, 2, 3, 4);?></pre>[/code] Quote Link to comment Share on other sites More sharing options...
ultrus Posted January 24, 2007 Author Share Posted January 24, 2007 jesirose, effigy,Sorry for the lack of clearification. I abreviated the script for forums simplicity. I'm actually converting Delphi and Visual Basic [i]usage[/i] examples into php usage examples. I'm communicaing with text to audio conversion software using the Microsoft COM object. The full Delphi example script looks like this:[code]procedure TForm1.DisplaySpeedSettings(Voice: String); var Currrent: Integer; Default: Integer; Min: Integer; Max: Integer; begin TextAloudObject.GetVoiceSettings(Voice, 'speed', current, default, min, max); ShowMessage(Format('Current: %d, Defaut: %d, Min: %d, Max: %d', [current, default, min, max])) end;[/code]Voice is a string specified earlier on. 'speed' is a string that can also be 'volume' or 'pitch'.I think I understand the reasoning behind the reference. I'm not sure on usage.I'm trying to read the current speed, default speed, minimum speed, and maximum speed from this other server using the function they provided. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 I think you need to look into passing variables by reference. Quote Link to comment Share on other sites More sharing options...
ultrus Posted January 24, 2007 Author Share Posted January 24, 2007 Awesome. I will look into this. Thanks for the help. :) Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 Sorry, I missed the line where you said you didn't know how to use them. http://www.php.net/manual/en/language.references.php Quote Link to comment Share on other sites More sharing options...
Hypnos Posted January 24, 2007 Share Posted January 24, 2007 Pass by reference, use a class, use global vars, or return an array. For the second line, printf/sprintf should work once you get the vars coming back in.Example using a class:[code]<?phpclass serverObject{ var $min; function Getsettings($min) { $this->$min = $min + 15; }}$gs = new serverObject;$gs->Getsettings(30);echo $gs->min;printf("Min: %d", $gs->min);[/code]I can't really help more than that without seeing more code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.