Autor Beitrag
OliverN_26
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 12:24 
Hallo

Wie kann ich ein in PHP existierendes Array so an Delphi übergeben, dass ich nachher in Delphi einfach auf die entsprechenden Werte zugreifen kann?
Ich probier mir da grad nen Wolf und hab mich glaub ich in eine komplett falsche Richtung bewegt.

PHP
ausblenden PHP-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
$zaehler = 0;
$service = array();
$result  = mysql_query("SELECT * FROM sk_schnittstelle_historie ORDER BY umschh_id ASC");
while($felder = mysql_fetch_assoc($result)) {  
  $service[$zaehler]['id']       = $felder['umschh_id'];
  $service[$zaehler]['aufgabe']  = $felder['umschh_aufgabe'];
  $service[$zaehler]['kurztext'] = utf8_encode($felder['umschh_text']);
  $service[$zaehler]['text']     = utf8_encode($felder['umschh_beschreibung']);
  $zaehler++;
}
echo json_encode($service);


DELPHI
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Services_laden;
var
  sl : TStringList;
  data : Array[0..25of String;
begin
  sl := TStringlist.Create;
  sl.Add('Merker=87');

  try
    data := IdHTTP1.Post('http://' + Hostname + '/mds/dp/sql/select.php',sl);
    showmessage(data[0]);
  except
    Exit;
  end;

  sl.Free;
end;


Vielen Dank für jede Hilfe.

lg
Oliver
baumina
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 305
Erhaltene Danke: 61

Win 7
Delphi 10.2 Tokyo Enterprise
BeitragVerfasst: Fr 15.11.13 12:53 
Ich habe das hier gefunden, evtl. hilft dir dieses Beispiel ja:

www.delphipraxis.net...ttp-post-senden.html
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 12:59 
Hallo

Leider nicht, da mir die Übergabe von Variablen klar ist.
Mein Ziel das PHP Array so nach Delphi zu übertragen dass ich die jeweiligen Zeilen/Felder entsprechend anspringen kann .. und genau da ist mein Problem.
Ich weiß wie ich ein Array erstelle/anspreche in PHP und Delphi einzeln. Wie ich Variablen von PHP nach Delphi bekomme weiß ich auch .. nur halt nicht wie das mit einem Array funktionieren soll.
Lemmy
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 792
Erhaltene Danke: 49

Windows 7 / 10; CentOS 7; LinuxMint
Delphi 7-XE10.1, VS 2015
BeitragVerfasst: Fr 15.11.13 13:01 
hi,

da sollte doch JSON das richtige Format sein.... Mit XE5 lässt sich das auch recht schmerzfrei verarbeiten, für andere Versionen gibts auch Implementierungen von Fremdherstellern....
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 13:04 
Ich denke auch dass ich auf PHP Seite nichts mehr ändern muß und JSON der richtige Weg ist.
Wie aber empfange ich den PHP-Request mit Delphi? Ich hab das Gefühl das ist letztendlich immer ein String. Irgendwie muß ich doch nachher die einzelnen Felder anspringen können?
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 14:22 
Nun ja .. ich nutze Delphi 7 Enterprise .. hättest du evt ein Beispiel für einen Fremdanbieter?
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Fr 15.11.13 16:14 
Hier gibts ein OpenSource Projekt, habs noch nicht verwendet, steht aber auf meiner ToDo Liste.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 15.11.13 16:56 
Die hier habe ich schon verwendet. Der Code ist innen drin sehr seltsam, aber schnell und von der Benutzung her ganz angenehm.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 17:08 
SuperObject hab ich auch gefunden und da jeder schreibt es wäre so einfach hab ich mir die letzten 2 Stunden daran die Zähne zerbissen, da ich immer eine "Integer Überlauf" Exception bekomme.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Services_laden;
var
  sl : TStringList;
  OB : ISuperObject;
  i : integer;
begin
  sl := TStringlist.Create;
  sl.Add('Merker=87');

  try
    OB := SO(IdHTTP1.Post('http://' + Hostname + '/mds/dp/sql/select.php',sl));
    for i := 0 to OB.AsArray.Length - 1 do
      ShowMessage(OB.AsArray[i].S['text']);
  except
    Exit;
  end;

  sl.Free;
end;


In die Funktion (an die markierte Stelle) springt er in der superobject.pas
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
class function TSuperAvlEntry.Hash(const k: SOString): Cardinal;
var
  h: cardinal;
  i: Integer;
begin
  h := 0;
{$Q-}
  for i := 1 to Length(k) do
    h := h*129 + ord(k[i]) + $9e370001;  // ****** Fehlerzeile ******
{$Q+}
  Result := h;
end;
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 17:16 
JSON Rückgabe sieht übrigens so aus:
Einloggen, um Attachments anzusehen!
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Fr 15.11.13 17:55 
@iKilledKenny:
Mit in den Source geschriebenen Testdaten klappt es .. mit meiner JSON Rückgabe bekomm ich ne Exception 'Ungültige Typenumwandlung'.
Wobei ich denke dass "SuperObject" mehr das wäre wonach ich suche .. grad weils auch um Arrays geht. Scheint einfach ansprechbar zu sein .. wenns denn läuft :-(

Mein Kopf :-(