4

I have an empty Delphi ClientDataSet CDS File setup with all the Columns/Headers/Datatypes that I need. I want to use PHP to append an associative array into CDS rows. Is this possible?

The array could simply be:

{
    1: {Name:Captain, Phone:18001234567}
    2: {Name:Jack, Phone:18009876543}
    3: {Name:Sparrow, Phone:18887892345}
}

I've selected PHP because I'm proficient with the language and my web server is a shared-linux host. Basically I cannot run Delphi here. I'm open to other options that could work in this environment. Thanks!

EDIT:

See the comments on this post for my resolution.

skibulk
  • 3,088
  • 1
  • 34
  • 42
  • 4
    +1 for a well asked question. `TClientDataSet` is a very proprietary Delphi/C++Builder local dataset (written in C++), and the format has never been published until recent RAD Studio releases included the source. I'm not aware of any way to access it from any other languages or platforms. I would have thought that if it was possible they would have included it in RadPHP, but (at least as far as XE2) they didn't. – Ken White May 31 '12 at 01:50
  • Just as an aside, have you considered running a Delphi app under Wine, and doing the work between it and your PHP code? It should be fairly easy to implement, since you're only talking about communicating data and not dealing with a UI or OS-level work. – Ken White May 31 '12 at 03:01
  • your json data is not array . number identifier could is invalid in delphi. – MajidTaheri May 31 '12 at 05:00
  • see http://stackoverflow.com/a/9988785/119609 – Vladimir Ulchenko May 31 '12 at 05:52
  • @Ken White - Unfortunately I cannot install wine on my shared host. – skibulk May 31 '12 at 12:26
  • @MajidTaheri - The array provided is just a sketch of sample data. In practice I could just parse each row one by one: {Name:John, Phone:15551236789} – skibulk May 31 '12 at 12:29
  • 1
    I presume you've decided you can't save the CDS in XML format (instead of the default proprietary binary) and work with it that way? (Of course you have; if you could just use XML, you wouldn't need the CDS.) Sorry; I'm out of suggestions at this point. The only Linux alternatives I can think of are FreePascal (which has no CDS support) or an old version of Kylix (which would need to be enterprise or architect SKUs, IIRC, to support CDS - pro didn't include it). – Ken White May 31 '12 at 12:33
  • @Ken White Right now I'm reading up on how to transform the XML into a CDS file. Building the XML is soooo simple! Do I just save it to binary XML format and then rename the file extension to .cds? I'm not sure how I will know which encoding technique delphi is using: http://en.wikipedia.org/wiki/Binary_XML – skibulk May 31 '12 at 12:37
  • 1
    I'm not sure Delphi uses a standard binary_XML encoding, unfortunately. CDS was around before then, I think, and I suspect Borland rolled their own at the time. It was part of their big "we do client-server apps" thing before they became Inprise, IIRC. – Ken White May 31 '12 at 12:50
  • @KenWhite Thanks for all your insight. I've given up on compiling a CDS, but I have discovered that my third-party software oddly enough accepts an uncompiled XML document that has been renamed with a .cds extension. I wouldn't in a million years have expected such behavior, I don't even know what prompted me to try it. It just works! – skibulk Jun 01 '12 at 22:28
  • Glad it worked out for you. They apparently used the `.XML` format, but gave it a filename with the other extension. Not sure how you decided to try it that way, but it's great it worked. :-) – Ken White Jun 01 '12 at 22:32
  • @KenWhite Actually, when I open up the original .cds files in a text editor, they are encoded! I have no clue how this is working, but I'm happy. – skibulk Jun 01 '12 at 22:36

1 Answers1

1

I recommend you to not write direct to the cds files.

Instead you can use a common xml for both applications (PHP and Delphi) and on the delphi side you load and save it using XML Transformation with TXmlTransformProvider and on the PHP side you just write it to the XML as you always do.

Take a look here on how to setup on delphi.

--UPDATE

If you realy need to change direct the cds file (using xml format) you can just add a new to the cds file considering the cds format is xml like this:

<?xml version="1.0" standalone="yes"?>  
<DATAPACKET Version="2.0">
    <METADATA>
        <FIELDS>
            <FIELD attrname="Name" fieldtype="string" WIDTH="24"/>
            <FIELD attrname="Capital" fieldtype="string" WIDTH="24"/>            
        </FIELDS>
        <PARAMS DEFAULT_ORDER="1" PRIMARY_KEY="1" LCID="2057"/>
    </METADATA>
    <ROWDATA>
        <ROW Name="Argentina" Capital="Buenos Aires"/>
        <ROW Name="Bolivia" Capital="La Paz"/>
        <ROW Name="Brazil" Capital="Brasilia"/>
        <ROW Name="Canada" Capital="Ottawa"/>        
        <ROW Name="United States of America" Capital="Washington"/> 
        //Add your new ROW tag here with your data       
    </ROWDATA>
</DATAPACKET>
Diego Garcia
  • 1,134
  • 1
  • 12
  • 25
  • I want to automate the creation of the CDS files (I need to create hundreds each year). I want to create them without having to launch Delphi and process each one individually... if push comes to shove I may have to take this route though – skibulk May 31 '12 at 02:15
  • This way that I've sayed you dont even need an CDS file, just the xml one. The clientdataset will handle direct the xml content. – Diego Garcia May 31 '12 at 02:20
  • I still need the CDS file because I'm using it with closed-source third party software. If it were my own I could code in TXmlTransformProvider support. Regrettably, I cannot in this situation. Thanks for your input. – skibulk May 31 '12 at 02:28
  • 1
    Now I see your problem, this way you could just add a new ROW Tag with your data to the ROWDATA tag inside the cds file. – Diego Garcia May 31 '12 at 03:00