![]() |
Problem mit php script
Kann das jemand bitte in delphi übersetzen:
function new_coord($x,$y) { $x = (string) (($x + 250) / 0.5); $y = (string) (($y + 250) / 0.5); if($x < 0 || $y < 0) { return false; } return array('con' => substr($y, 0, 1).substr($x, 0, 1), 'sec' => substr($y, 1, 1).substr($x, 1, 1), 'sub' => substr($y, 2, 1) / 2 * 5 + substr($x, 2, 1) / 2); } |
Re: Problem mit php script
Delphi-Quellcode:
Auch wenn ich nicht verstehe, warum du das nicht selbst machst :?
function new_coord(var x, y: string): Variant;
begin x := IntToStr((StrToInt(x) + 250) * 2); y := IntToStr((StrToInt(y) + 250) * 2); if (x < 0) or (y < 0) then begin Result := false; Exit; end; Result := CreateVarArray([0, 2], varInteger); Result[0] := y[1] + x[1]; Result[1] := y[2] + x[2]; Result[2] := IntToStr(StrToInt(y[3]) div 10 + StrToInt(x[3]) div 2); end; |
Re: Problem mit php script
dax du hast da nen boolean result und benutzt das als array ? *nixblick*
|
Re: Problem mit php script
Ach Mist, das hab' ich ein { übersehen -.-
Generell kann ich aber sagen, das Übersetzungen von php nach Delphi oft schwer bis gar nicht möglich sind.. |
Re: Problem mit php script
jo. weil ich da fast alle variablen mit allem verwenden kann *g*
kein inttostr usw notwendig |
Re: Problem mit php script
Die einzige Möglichkeit ist, wie in der Übersetzung, Variants zu benutzen...
|
Re: Problem mit php script
hi,
hmhmhm. naja, erstens wäre es schön, wenn du die [code] tags benutzen würdest. und zweitens ist das nicht ganz leicht. denn in delphi solltest du vorher schon wissen, welchen typ die func zurückgeben soll (also nicht mal boolean und mal ein array). das wäre eventuell mit einem record oder einer kalsse zu lösen. achja und drittens ist der code fehlerhaft. du gibst einmal false zurück, wenn die bedingung zutriffst. dieses result wird aber sofort wieder mit einem array überschrieben.... ;) ich habs aber spaßeshalber mal trotzdem versucht zu übersetzen:
Delphi-Quellcode:
ohne gewähr
type
TNewCoordResult = record ok: boolean; Con, Sec, Sub: double; end; function new_coord(x, y: double): TNewCoordResult; var tempx, tempy: string; begin result.ok := true; tempx := floattostr((x + 250) / 0.5); tempy := floattostr((y + 250) / 0.5); if (tempx < 0) or (tempy < 0) then begin result.ok := false; exit; //edited: ganz wichtig ;) end; result.con := strtofloat(copy(floattostr(tempy), 0, 1) + copy(floattostr(tempx), 0, 1)); result.sec := strtofloat(copy(floattostr(tempy), 1, 1) + copy(floattostr(tempx), 1, 1)); result.sub := strtofloat(floattostr(strtofloat(copy(floattostr(tempy), 2, 1)) / 2 * 5) + floattostr(strtofloat(copy(floattostr(tempx), 2, 1)) / 2)); end; edit: oh meion gott, die letzte zeile ist aber mega unübersichtlich. @dax und supemuckl: man kanns auch ohne variants lösen.... man muss nur beim weiteren bearbeiten des results (der record) unterscheiden, ob das boolean false ist, oder ob die anderen werte gesetzt sind... edit2: jetzt wird die funktionsebene auch verlassen ;) Aenogym |
Re: Problem mit php script
Aenogym, du siehst da was falsch. return bewirkt in php, wie in C(++), dass die aktuelle Funktionseben auch noch verlassen wird ;)
|
Re: Problem mit php script
Zitat:
Aenogym |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz