Sign in Join
Wiki copytemporary

GolfmlClass: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# tgolfmlclass
22
33------------------------------------------------------------------------
44
55- A Lazarus/Free Pascal class to accept data via properties and write a well-formed golfml XML golf information exchange file.
66- It will also read a well-formed golfml XML golf information exchange file and present the data via properties.
77- You can have as many Courses and Tee positions as you like (they are stored in internal dynamic arrays) , but only one Golf Club. Holes can be 1 up to 18.
88- ugolfmlclass.pas is available for download [from here](http://code.google.com/p/golfml/source/browse/#svn%2Fgolfml%2Fcoursewriter%2Fsource%2F2.x)
99- An example application Golfml Coursewriter is available [from here](http://code.google.com/p/golfml/wiki/CourseWriter)
1010- To learn more about golfml visit <http://code.google.com/p/golfml/>
1111
1212------------------------------------------------------------------------
1313
1414## Declaration
1515
1616`Uses: ugolfmlclass`\
1717`Var: GolfmlClass:TGolfMLClass;`
1818
1919------------------------------------------------------------------------
2020
2121## Methods
2222
2323- function *InitOK:* boolean
2424
2525` * Returns TRUE = Success, FALSE = Fatal Error`
2626
2727- Procedure *Reset* (use before re-assigning a new club and courses)
2828
2929Both methods initialise all variables in the class and prepare it for use. The Function InitOK only returns TRUE if all is well.
3030
3131FORM CREATE EVENT EXAMPLE:
3232
3333`GolfmlClass:=TGolfMLClass.Create; `\
3434`If NOT GolfmlClass.InitOK then Halt;`
3535
3636- function MakeGolfmlFile:Boolean;
3737
3838` * Returns TRUE=Success.  Overwrites any file with the same name (set in CourseXMLPath property)`
3939
4040- function GetCourseInfoFromFile:boolean
4141
4242` * Returns TRUE=Success`
4343
4444Reading
4545
4646- GolfmlClass.GetCourseInfoFromFile is called *before* any properties are read and after CourseXMLPath has been set.
4747
4848Writing
4949
5050- GolfmlClass.!MakeGolfmlFile should only be called *after* all the data has been set using the properties (see below)
5151
5252------------------------------------------------------------------------
5353
5454## Properties Read/Write
5555
5656`// Club-wide Properties`\
5757`property ClubAmeneties[iIndex:Integer]: string // 0..`\
5858`property ClubComments[iIndex:Integer]: string // 0..`\
5959`// Both are dynamic properties that grow as assigned.  They should be assigned in order for reliable results.`\
6060`// The type and description are separated by a comma`\
6161`// GolfmlClass.ClubAmeneties[0]:='amenity type,amenity description';`\
6262`// GolfmlClass.ClubAmeneties[1]:='amenity type,amenity description';`\
63-\
64-\
63+
6564`property CourseXMLPath: string // Note: THIS NOT CHECKED FOR VALIDITY by tgolfmlclass.`\
6665`property ClubName: string`\
6766`property ClubCountry: string`\
6867`property ClubCountryCode: string`\
6968`property ClubMunicipality: string`\
7069`property ClubRegion: string`\
7170`property ClubStreet: string`\
7271`property ClubPostCode: string`\
7372`property ClubWebsite: string`\
7473`property ClubPhone: string`\
75-\
76-\
74+
7775`// Course-wide Properties`\
7876`// Change courses by changing the CourseIndex property (0-based)`\
7977`property CourseIndex:Cardinal  //(zero-based)`\
8078`Property CourseName:String`\
8179`Property CoursePar:Cardinal // Total Par value of the course`\
8280`Property CourseNumberOfHoles:Cardinal //(1-based, usually 9 or 18)`\
83-\
84-\
81+
8582`// Tee Position-wide Properties`\
8683`// Change Tee sets by changing the TeeColourIndex property (0-based)`\
8784`// Normally, TeeColourIndex is normally from Gold (0) to Red (5)`\
8885`//  but it can be any scheme you like as long as the TeeColour and`\
8986`// TeeGender agree.`\
9087`Property TeeColourIndex:Cardinal  //(zero-based)`\
9188`property TeeTitle: string // Can be anything: 'Competition', 'Regular', 'Ladies'`\
9289`property TeeColour: string // i.e. 'gold', 'black', 'white', 'yellow', 'blue', 'red'`\
9390`property TeeGender: string // 'gentlemen' or 'ladies'`\
9491`Property CourseRating:Single`\
9592`Property SlopeRating:Cardinal`\
96-\
97-\
98-\
93+
9994`// Hole Properties`\
10095`// Change Hole by changing the HoleIndex property (0-17)`\
10196`property HoleIndex:Cardinal //(zero-based)`\
10297`Property Par:Cardinal`\
10398`Property StrokeIndex:Cardinal`\
10499`Property Metric:Boolean // Affects Distance conversion. Metric=TRUE means distances in meters`\
105100`Property TeeDistanceMetres:Cardinal`\
106101`Property TeeDistanceYards:Cardinal`\
107102`// Note Tee Distances are automatically converted yards->meters and meters->yards.`\
108103`// Only specify yards OR meters when setting Tee Distances`\
109-\
104+
110105`// Stylesheet writing properties`\
111106`Property IncludeScoreCardStylesheetReference:Boolean`\
112107`Property IncludePlayerScoreCardStylesheetReference:Boolean`\
113108`Property ScoreCardPlayerName:String`\
114109`Property ScoreCardPlayerGender:String`\
115110`Property ScoreCardPlayerDateOfBirth:String`\
116111`Property ScoreCardPlayerHandicap:Single`\
117-\
112+
118113`=== Properties Read Only ===`\
119-\
114+
120115`Property Version:String readonly;`\
121116`Property InTeeDistance:Cardinal; // Calculated value for each course.Metric determines metres or yards`\
122117`Property OutTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards`\
123118`Property TotalTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards`\
124119`Property CourseTotalPar:Cardinal // Calculated value for each course.`\
125120`Property BogeyRating:Single // Calculated value for each tee position.`\
126121`property MaxCourseIndex:Cardinal // Highest value for CourseIndex`\
127122`Property MaxTeeColourIndex:Cardinal`\
128123`Property ClubMaxAmenitiesIndex:Cardinal`\
129124`Property ClubMaxCommentsIndex:Cardinal`
130125
131126- MaxIndex-type properties help when setting up a loop to read the indexed property values e.g.
132127
133128`With GolfmlClass do`\
134129`  Begin`\
135130`    For iCount:=0 to MaxCourseIndex do`\
136131`     begin`\
137132`        CourseIndex:=iCount; // Set the course number`\
138133`        MyStringList.Add(CourseName); // Read data for this course`\
139134`    end;`\
140135`  End;`
141136
142137------------------------------------------------------------------------
143138
144139SIMPLE WRITING EXAMPLE: To set the Par of Hole 3 to the value 5 on the first course at Tee-position 1:
145140
146141`GolfmlClass.CourseIndex:=0;`\
147142`GolfmlClass.TeeIndex:=0;`\
148143`GolfmlClass.HoleIndex:=2;`\
149144`GolfmlClass.Par:=5;`
150145
151146------------------------------------------------------------------------
152147
153148SIMPLE READING EXAMPLE: To get the Par of Hole 3 on the first course at Tee-position 1:
154149
155150`GolfmlClass.CourseIndex:=0;`\
156151`GolfmlClass.TeeIndex:=0;`\
157152`GolfmlClass.HoleIndex:=2;`\
158153`cParVariable:=GolfmlClass.Par;`
159154
160155------------------------------------------------------------------------
161156
162157#### How to populate the data before calling MakeGolfmlFile
163158
164159Normally you would set up 3 nested loops, and assign values to properties within the loops according to their scope.
165160
166161MULTIPLE WRITING EXAMPLE:
167162
168163`GolfmlClass.Reset;`\
169164`...Set Club-wide properties...`\
170165`For CourseLoop:=0 to ... DO`\
171166`  GolfmlClass.CourseIndex:=CourseLoop; // Write data to this course`\
172167`  ...assign Course-wide properties...`\
173168`  For TeeLoop:=0 to .. DO`\
174169`    GolfmlClass.TeeColourIndex:=TeeLoop; // Write data to this Tee Position in this course`\
175170`    ...assign Tee Position-wide properties...`\
176171`    For HoleLoop:=0 to 17 (or 9) DO`\
177172`        GolfmlClass.HoleIndex:=HoleLoop; // Write data to this hole in this Tee Position in this course`\
178173`        ...assign Hole properties....`\
179174`    end; // next hole`\
180175`  end; // next tee position`\
181176`end; // next course`\
182177`GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';`\
183178`GolfmlClass.MakeGolfmlFile;`
184179
185180------------------------------------------------------------------------
186181
187182#### How to retrieve the data after calling GetCourseInfoFromFile
188183
189184MULTIPLE READING EXAMPLE
190185
191186`GolfmlClass.Reset;`\
192187`GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';`\
193188`GolfmlClass.GetCourseInfoFromFile;`\
194-\
189+
195190`//Retrieve the Club properties first.`\
196191`sName:=GolfmlClass.Clubname;`\
197192`...etc`\
198193`//Now get all the Club Amenities via a loop.`
199194
200195*Remember the amenity type and description are separated by a comma*
201196
202197Here's a function to separate them
203198
204199`procedure SplitAmenety(var fAmenityType,fAmenetyValue:String;Const aString:String);`\
205200`// Changes fAmenityType, fAmenetyValue`\
206201`// Uses C_AMENETYDELIMITERCHAR`\
207202`Var`\
208203`   i:Integer;`\
209204`begin`\
210205`     if Length(aString)=0 then exit;`\
211206`     i:=Pos(C_AMENETYDELIMITERCHAR,aString);`\
212207`     If i > 1 then`\
213208`     Begin`\
214209`          fAmenityType:=LeftStr(aString,i-1);`\
215210`          fAmenetyValue:=RightStr(aString,Length(aString)-i);`\
216211`     end;`\
217212`end;`\
218-\
213+
219214`Var sAmenityType, sAmenityValue:String;`\
220215`For iLoop:=0 to GolfmlClass.ClubMaxAmenitiesIndex do`\
221216`  begin`\
222217`       // Initialise strings to pass by value to procedure`\
223218`       sAmenityType:='';`\
224219`       sAmenityValue:='';    `
225220
226221`SplitAmenety(sAmenityType,sAmenityValue,GolfmlClass.ClubAmeneties[iLoop]);`\
227222`       MyAmenityTypeList.Add(sAmenityType);`\
228223`       MyAmenityValueList.Add(sAmenityValue);`\
229224`  End;`
230225
231226... fetch the ClubComments in the same way...
232227
233228`For iLoop:=0 to GolfmlClass.ClubMaxCommentsIndex do`\
234229`  begin `\
235230`       MyStringList.Add(GolfmlClass.ClubComments[iLoop]);`\
236231`  End;`
237232
238233Retrieve the data for each hole in each tee set in each course via a loop
239234
240235`For CourseLoop:=0 to GolfmlClass.MaxCourseIndex DO`\
241236`  GolfmlClass.CourseIndex:=CourseLoop; // Read data from this course`\
242237`  ...get Course-wide properties...`\
243238`  .. get Hole pars and strokeindexes (via a holeindex loop)`\
244239`  For TeeLoop:=0 to GolfmlClass.MaxTeeColourIndex DO`\
245240`    GolfmlClass.TeeColourIndex:=TeeLoop; // Read data from this Tee Position in this course`\
246241`    ...get Tee Position-wide properties for this course`\
247242`    .... get Course and Slope ratings.  Get the Tee colours, titles and genders...`\
248243`    For HoleLoop:=GolfmlClass.CourseNumberOfHoles DO`\
249244`        GolfmlClass.HoleIndex:=HoleLoop; // Read data from this hole in this Tee Position in this course`\
250245`        GolfmlClass.Metric:=TRUE; //=FALSE would retrieve yards`\
251246`        ...Get Hole distances in metres`\
252247`    end; // next hole`\
253248`  end; // next tee position`\
254249`end; // next course`
255250
256251## Summary
257252
258253Each property has a *scope* within a Club, Course, Tee-position or Hole.
259254
260255..for instance:
261256
262257- Distances are for a course, tee-position and hole
263258- StrokeIndexes are for a course and hole only.
264259- CourseRating is for a course and tee-position only
265260
266261GolfmlClass tries to make this as simple as possible for reading and writing by having 3 "master" index properties for Course, TeePosition and Hole. (There is only ever one Club) In this way, you always know the scope of the property that you are trying to read or write.
267262
268263---
269264*From the Free Pascal wiki, page "GolfmlClass", as it stood on 2014-05-27 after a change by BigChimp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
270265Category: Components
271266Category: XML

Back to history