0

I've just installed Delphi 7 for Personal Use and I'm trying to convert a delphi ClientDataSet file to dfXMLUTF8. All I really need is the xml structure. This site suggests that running 4 lines of code will generate the output I desire. Note however that My file is .cds, not .dat as in the example. I don't know if this makes a difference.

ClientDataSet1.Active := false;
ClientDataSet1.CreateDataSet;
ClientDataSet1.LoadFromFile('MyBinaryFile.dat');
ClientDataSet1.SaveToFile('MyXMLFile.XML', dfXMLUTF8);

I'm receiving errors and since I've never really used Delphi before and I'm hoping somebody who knows what they are doing could just post the very short xml structure for me. Here's the file(486 bytes) I'm working with. I will award correct answer to the first poster with full dfXMLUTF8 output. Thanks!

Update:

Okay I just started the project from scratch and I think I have it somewhat setup. I have added uses DBClient;, var ClientDataSet1: TClientDataSet, and lastly the procedure:

ClientDataSet1.LoadFromFile('C:\Documents and Settings\XPMUser\Desktop\DelphiCDS\Master.cds');
  ClientDataSet1.SaveToFile('C:\Documents and Settings\XPMUser\Desktop\DelphiCDS\output.XML', dfXMLUTF8);

It throws the following error:

Access violation at address 004588B6 in module 'Project.exe'. Read of address 00000000.

Update2:

Here's what I ended up with:

unit Script3;

interface

uses
  Forms, DBClient;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;
  CDS: TClientDataSet;

implementation
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  CDS := TClientDataSet.Create(nil);
  try
    CDS.LoadFromFile('.\input.cds');
    CDS.SaveToFile('.\output.xml', dfXMLUTF8);
  finally
    CDS.Free;
  end;
end;

end.
skibulk
  • 3,088
  • 1
  • 34
  • 42
  • When you say "I'm receiving errors", it's extremely useful if you actually provide **the errors** in your question text, since we can't see your screen from where we are. Please edit your question and provide the **exact** error message you're getting. Thanks. – Ken White Nov 20 '12 at 01:06
  • I gave you **specific code** about how to create and use a `TClientDataSet` in code in my answer below. If you're getting that access violation, you're not using the code I posted. Please read again; you apparently missed the `CDS := TClientDataSet.Create(nil)` and `CDS.Free;` parts of it. – Ken White Nov 20 '12 at 02:27

1 Answers1

6

You're doing much more than you have to in order to accomplish the conversion. With the presumption that MyBinaryFile.dat is actually a binary format Delphi TClientDataSet file, these two lines of code (with no additional setup) will work:

ClientDataSet1.LoadFromFile('D:\Temp\MyBinaryFile.dat');
ClientDataSet1.SaveToFile('D:\Temp\MyXMLFile.xml', dfXMLUTF8);

Without knowing more about what your MyBinaryFile.dat is, and no information about the errors you're getting, it's pretty difficult to provide more information. Tested and working with the standard animals.cds in Delphi 7 (from C:\Program Files\Common Files\Borland Shared\Data in a standard D7 install on a Windowx XP virtual machine).

It seems, from your comment below, that the actual problem you're having is a compiler error about an unidentified identifier TClientDataSet when you try and create it in code. If you have a high enough SKU for Delphi 7 that includes TClientDataSet (IIRC, Professional and higher), you can just add DBClient to your uses clause:

implementation

uses 
  DBClient;

procedure TForm1.FormShow(Sender: TObject);
var
  CDS: TClientDataSet;
begin
  CDS := TClientDataSet.Create(nil);
  try
    CDS.LoadFromFile('MyBinaryFile.dat');
    CDS.SaveToFile('MyXMLFile.xml', dfXMLUTF8);
  finally
    CDS.Free;
  end;
end;

Or, better yet, if you're creating a VCL Forms application, just drop a TClientDataSet on your form; you'll find it on the DataAccess tab in the component palette.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • I'm an absolute beginner. I'm declaring [code]var ClientDataSet1: TClientDataSet;[/code] and receiving undeclared identifier TClientDataSet. – skibulk Nov 20 '12 at 01:54
  • My actual CDS file is linked on my opening question. I just don't know a single thing about Delphi. What variable type should CLientDataSet1 be? – skibulk Nov 20 '12 at 01:57
  • 1
    If TClientDataSet is available in the edition of Delphi 7 you're using (Professional and higher SKUs, IIRC), just add `DBClient` to your uses clause. (Or drop a `TClientDataSet` on your form from the `DBAccess` tab in the component palette.) If you'd mentioned that in your original question, I could have addressed that in my answer as well. – Ken White Nov 20 '12 at 01:58
  • Alright I think I added that correctly. How do I run this script? "Run" is grayed out. – skibulk Nov 20 '12 at 02:07
  • Updated the OP with my latest. – skibulk Nov 20 '12 at 02:24
  • 1
    Delphi isn't a scripting language. It's a compiled programming language that creates native Win32 executable files. You need to put the code in a project (File|New|VCL Forms Application or File|New|Other|Console Application), and then compile and run that project. StackOverflow isn't a programming tutorial site. You need to find a site that teaches the basics. Try [Delphi About](http://delphi.about.com) or [Marco Cantu's site](http://marcocantu.com). – Ken White Nov 20 '12 at 02:25