Re: 100% pure Win32 IDE



Craig Stuntz [TeamB] wrote:

A huge advantage of XML over INI files for those with Delphi
Enterprise is the XML data binding wizard. Just write a sample XML
config file, run the data binding wizard, and now you have an object
model for your configuration settings. So in a simple case your code
looks like this:

A huge advantage of DFM over XML for those with any edition of Delphi is the ability to easily stream components in and out of a persistent storage. Just derive your config object from TComponent, stream the component in and out, and now you have an object model for your configuration settings, without needing an expensive edition of Delphi or a XML engine.

Here's an example of streaming to/from a dataset field. Omit the ObjectTextToBinary and ObjectBinaryToText calls, and change TMemoField to TBlobField, to store the object in binary form (much more efficient but more difficult to troubleshoot while in Query Analyzer :D ):

procedure ObjectToField(AObject: TComponent; AField: TMemoField);
var
msBinaryDFM : TMemoryStream;
msTextDFM : TMemoryStream;
begin
msBinaryDFM := TMemoryStream.Create();
msTextDFM := TMemoryStream.Create();

try
msBinaryDFM.WriteComponent(AObject);
msBinaryDFM.Seek(0, soFromBeginning);

ObjectBinaryToText(msBinaryDFM, msTextDFM);
msTextDFM.Seek(0, soFromBeginning);

if not (AField.DataSet.State in dsEditModes) then
AField.DataSet.Edit();
try
AField.LoadFromStream(msTextDFM);
finally
AField.DataSet.Post();
end;

finally
msBinaryDFM.Free();
msTextDFM.Free();
end;
end;

procedure FieldToObject(AField: TMemoField; AObject: TComponent);
var
msBinaryDFM : TMemoryStream;
msTextDFM : TMemoryStream;
begin
msBinaryDFM := TMemoryStream.Create();
msTextDFM := TMemoryStream.Create();

try
AField.SaveToStream(msTextDFM);
msTextDFM.Seek(0, soFromBeginning);

ObjectTextToBinary(msTextDFM, msBinaryDFM);
msBinaryDFM.Seek(0, soFromBeginning);

msBinaryDFM.ReadComponent(AObject);

finally
msBinaryDFM.Free();
msTextDFM.Free();
end;
end;
.



Relevant Pages

  • Re: parsing config files from an api... xml?
    ... >> allows one to parse and edit, update various config files on linux. ... The way XML has developed, the only way to use it is by generating it ... produce a DOM tree and hand this over to Batik to produce PNG files. ...
    (comp.os.linux.development.system)
  • Re: OleDb Connection to XML File
    ... I do this for small config data stuff all the time. ... connect to an XML file with OLE DB. ... information about the connection string parameters. ... would be best to store it in a database-like storage area. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: My windows giveth xml and it taketh away! Include path!
    ... If you just call it .xml then you won't conflict with the special magic ... ..config files. ... >info in an xml file speak of only doing this for web programming in fact, ... > screensaver, reload it and see that the new values were there, and then ...
    (microsoft.public.dotnet.xml)
  • Re: "Next Generation" kernel configuration?
    ... >> You can have my simple flat file kernel config when you pry it from ... All my experiences with the linux visual kernel ... Wasn't even thinking XML. ...
    (freebsd-hackers)