[fpc-pascal] OOP and XML usage
Jorge Aldo G. de F. Junior
jagfj80 at gmail.com
Thu Jan 28 15:10:22 CET 2010
with my system would be simply something like
Type
TMyClass = Class(TXMLNode)
Private
fSomething : String;
Public
Constructor Create(Const aInstanceName : String); Override;
Class Function XMLTag: String; Override;
Published
Property Something : String Read fSomething Write fSomething;
End;
Constructor Create(Const aInstaceName : String);
Begin
Inherited Create(aInstanceName);
End;
Class Function XMLTag: String;
Begin
Result := 'MyTag';
End;
Factory.Register(TMyClass);
Whenever the xml loader finds a <mytag something="test"/> it will
create an instance of TMyClass and set the published properties
accordingly (Using RTTI)...
Theres another procedure (wich is virtual and can be overriden if
needed) that triggers events across the three... (wich are basically
dotted notation names...)
MyClass1.MyClass2.Test <-
Finds instance MyClass1,
Finds instance MyClass2 that is a child of MyClass1
then issues a DispatchStr in MyClass1 with Test as the message
string... (The pointer can be passed as to hold properties, values,
etc)...
(Im using this message system to allow brower events to be sent to
server side objects)
2010/1/27 Anthony Walter <sysrpl at gmail.com>:
> I've written some XML classes which expose themselves as interfaces.
> Usage goes something like this:
>
> procedure SaveSettings(const Settings: string);
> var
> Document: IDocument;
> Filer: IFiler;
> begin
> Document := CreateDocument;
> Filer := Document.ForceRoot('test') as IFiler;
> Filer.WriteTime('time', Now);
> Filer.WriteString('application', Application.ExeName);
> Document.SaveToFile(Settings);
> end;
>
> <test><time>21:11:17</time><application>test.exe</application></test>
>
> procedure ShowPerson;
> var
> Document: IDocument;
> Root: INode;
> begin
> Document := CreateDocument;
> Filer := Document.ForceRoot('data');
> Root.ForceNode('person/age').Value = 17;
> Root.FindNode('person[age = 17]').Filer.Write('Jason');
> Root.Filer.Write('person/salary', 10000);
> ShowMessage(Document.Text);
> end;
>
>
> <data><person><age>17</age><name>Jason</name><salary>10000</salary></person><data>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list