>LOCAL CursorDefinitions AS String > >TEXT TO m.CursorDefinitions NOSHOW FLAGS 1 ><?xml version="1.0" encoding="windows-1252"?> ><xsd:schema id="VFPSchema" > targetNamespace="http://microsoft.com" > xmlns="http://microsoft.com" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified"> > <xsd:element name="VFPData"> > <xsd:complexType> > <xsd:choice maxOccurs="unbounded"> > <!-- the cursor definitions --> > <!-- PERSONS --> > <xsd:element name="person"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="name"> > <xsd:simpleType> > <xsd:restriction base="xsd:string"> > <xsd:maxLength value="50"/> > </xsd:restriction> > </xsd:simpleType> > </xsd:element> > <xsd:element name="gender"> > <xsd:simpleType> > <xsd:restriction base="xsd:string"> > <xsd:maxLength value="1"/> > </xsd:restriction> > </xsd:simpleType> > </xsd:element> > <xsd:element name="born" type="xsd:date"/> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > <!-- CARS --> > <xsd:element name="car"> > <xsd:complexType> > <xsd:sequence> > <xsd:element name="brand"> > <xsd:simpleType> > <xsd:restriction base="xsd:string"> > <xsd:maxLength value="50"/> > </xsd:restriction> > </xsd:simpleType> > </xsd:element> > <xsd:element name="model"> > <xsd:simpleType> > <xsd:restriction base="xsd:string"> > <xsd:maxLength value="50"/> > </xsd:restriction> > </xsd:simpleType> > </xsd:element> > <xsd:element name="year" type="xsd:int"/> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > </xsd:choice> > </xsd:complexType> > </xsd:element> ></xsd:schema> >ENDTEXT > >STRTOFILE(m.CursorDefinitions, "cursors.xsd") > >CreateCursorFromXSD("persons", "person") >CreateCursorFromXSD("cars", "car") > >SELECT Persons >BROWSE NOWAIT > >SELECT Cars >BROWSE NOWAIT >MOVE WINDOW Cars BY 5, 10 > >FUNCTION CreateCursorFromXSD (CursorName AS String, CursorType AS String) AS Boolean > > LOCAL CursorCreator AS String > LOCAL XSD AS MSXML2.DOMDocument60 > LOCAL CursorDefinition AS MSXML2.IXMLDOMNodeList > > m.XSD = CREATEOBJECT("MSXML2.DOMDocument.6.0") > m.XSD.Async = .F. > m.XSD.Load("cursors.xsd") > m.XSD.Setproperty("SelectionNamespaces", "xmlns:xsd='http://www.w3.org/2001/XMLSchema'") > m.CursorDefinition = m.XSD.Selectnodes("//xsd:element[@name='" + m.CursorType + "']") > > SET TEXTMERGE DELIMITERS TO "««", "»»" > > USE IN SELECT(m.CursorName) > > TEXT TO m.CursorCreator TEXTMERGE NOSHOW FLAGS 1 PRETEXT 3 > <?xml version="1.0" encoding="windows-1252"?> > <VFPData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> > <xsd:schema id="VFPData"> > <xsd:element name="VFPData" msdata:IsDataSet="true"> > <xsd:complexType> > <xsd:choice maxOccurs="unbounded"> > ««m.CursorDefinition.item(0).xml»» > </xsd:choice> > </xsd:complexType> > </xsd:element> > </xsd:schema> > <««m.CursorType»» /> > </VFPData> > ENDTEXT > > SET TEXTMERGE DELIMITERS > > XMLTOCURSOR(m.CursorCreator, m.CursorName) > >ENDFUNC >Hi Antonio el al,
create cursor MyCursor1 (field1 c(10), field2 n(12,2), field3 i)and so on. But I wanted to have the structure of these cursors outside of the code so that I can change it, if necessary, without changing the program. So the approach I though is as follows:
*** text file MyCursors.txt <Cursor1Name>field1 c(10), field2 n(12,2), field3 i</Cursor1Name> <Cursor2Name>field1 c(40), field2 n(1,2), field3 i</Cursor21Name>So, at run-time, I can read this .txt (or other extension) file using filetostr(). And, then using STREXTRACT() get the structure of any cursor. It will be a very small Function. Then use the extracted line of the Structure in the CREATE CURSOR command.