Sign in Join
Wiki copytemporary

GolfmlClass: what changed

Revision 2 to 3. 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
16-`Uses: ugolfmlclass`\
17-`Var: GolfmlClass:TGolfMLClass;`
16+``` pascal
17+Uses: ugolfmlclass
18+Var: GolfmlClass:TGolfMLClass;
19+```
1820
1921------------------------------------------------------------------------
2022
2123## Methods
2224
2325- function *InitOK:* boolean
2426
25-` * Returns TRUE = Success, FALSE = Fatal Error`
27+```text
28+ * Returns TRUE = Success, FALSE = Fatal Error
29+```
2630
2731- Procedure *Reset* (use before re-assigning a new club and courses)
2832
2933Both methods initialise all variables in the class and prepare it for use. The Function InitOK only returns TRUE if all is well.
3034
3135FORM CREATE EVENT EXAMPLE:
3236
33-`GolfmlClass:=TGolfMLClass.Create; `\
34-`If NOT GolfmlClass.InitOK then Halt;`
37+``` pascal
38+GolfmlClass:=TGolfMLClass.Create;
39+If NOT GolfmlClass.InitOK then Halt;
40+```
3541
3642- function MakeGolfmlFile:Boolean;
3743
38-` * Returns TRUE=Success.  Overwrites any file with the same name (set in CourseXMLPath property)`
44+```text
45+ * Returns TRUE=Success. Overwrites any file with the same name (set in CourseXMLPath property)
46+```
3947
4048- function GetCourseInfoFromFile:boolean
4149
42-` * Returns TRUE=Success`
50+```text
51+ * Returns TRUE=Success
52+```
4353
4454Reading
4555
4656- GolfmlClass.GetCourseInfoFromFile is called *before* any properties are read and after CourseXMLPath has been set.
4757
4858Writing
4959
5060- GolfmlClass.!MakeGolfmlFile should only be called *after* all the data has been set using the properties (see below)
5161
5262------------------------------------------------------------------------
5363
5464## Properties Read/Write
5565
56-`// Club-wide Properties`\
57-`property ClubAmeneties[iIndex:Integer]: string // 0..`\
58-`property ClubComments[iIndex:Integer]: string // 0..`\
59-`// Both are dynamic properties that grow as assigned.  They should be assigned in order for reliable results.`\
60-`// The type and description are separated by a comma`\
61-`// GolfmlClass.ClubAmeneties[0]:='amenity type,amenity description';`\
62-`// GolfmlClass.ClubAmeneties[1]:='amenity type,amenity description';`\
66+``` pascal
67+// Club-wide Properties
68+property ClubAmeneties[iIndex:Integer]: string // 0..
69+property ClubComments[iIndex:Integer]: string // 0..
70+// Both are dynamic properties that grow as assigned. They should be assigned in order for reliable results.
71+// The type and description are separated by a comma
72+// GolfmlClass.ClubAmeneties[0]:='amenity type,amenity description';
73+// GolfmlClass.ClubAmeneties[1]:='amenity type,amenity description';
6374
64-`property CourseXMLPath: string // Note: THIS NOT CHECKED FOR VALIDITY by tgolfmlclass.`\
65-`property ClubName: string`\
66-`property ClubCountry: string`\
67-`property ClubCountryCode: string`\
68-`property ClubMunicipality: string`\
69-`property ClubRegion: string`\
70-`property ClubStreet: string`\
71-`property ClubPostCode: string`\
72-`property ClubWebsite: string`\
73-`property ClubPhone: string`\
75+property CourseXMLPath: string // Note: THIS NOT CHECKED FOR VALIDITY by tgolfmlclass.
76+property ClubName: string
77+property ClubCountry: string
78+property ClubCountryCode: string
79+property ClubMunicipality: string
80+property ClubRegion: string
81+property ClubStreet: string
82+property ClubPostCode: string
83+property ClubWebsite: string
84+property ClubPhone: string
7485
75-`// Course-wide Properties`\
76-`// Change courses by changing the CourseIndex property (0-based)`\
77-`property CourseIndex:Cardinal  //(zero-based)`\
78-`Property CourseName:String`\
79-`Property CoursePar:Cardinal // Total Par value of the course`\
80-`Property CourseNumberOfHoles:Cardinal //(1-based, usually 9 or 18)`\
86+// Course-wide Properties
87+// Change courses by changing the CourseIndex property (0-based)
88+property CourseIndex:Cardinal //(zero-based)
89+Property CourseName:String
90+Property CoursePar:Cardinal // Total Par value of the course
91+Property CourseNumberOfHoles:Cardinal //(1-based, usually 9 or 18)
8192
82-`// Tee Position-wide Properties`\
83-`// Change Tee sets by changing the TeeColourIndex property (0-based)`\
84-`// Normally, TeeColourIndex is normally from Gold (0) to Red (5)`\
85-`//  but it can be any scheme you like as long as the TeeColour and`\
86-`// TeeGender agree.`\
87-`Property TeeColourIndex:Cardinal  //(zero-based)`\
88-`property TeeTitle: string // Can be anything: 'Competition', 'Regular', 'Ladies'`\
89-`property TeeColour: string // i.e. 'gold', 'black', 'white', 'yellow', 'blue', 'red'`\
90-`property TeeGender: string // 'gentlemen' or 'ladies'`\
91-`Property CourseRating:Single`\
92-`Property SlopeRating:Cardinal`\
93+// Tee Position-wide Properties
94+// Change Tee sets by changing the TeeColourIndex property (0-based)
95+// Normally, TeeColourIndex is normally from Gold (0) to Red (5)
96+// but it can be any scheme you like as long as the TeeColour and
97+// TeeGender agree.
98+Property TeeColourIndex:Cardinal //(zero-based)
99+property TeeTitle: string // Can be anything: 'Competition', 'Regular', 'Ladies'
100+property TeeColour: string // i.e. 'gold', 'black', 'white', 'yellow', 'blue', 'red'
101+property TeeGender: string // 'gentlemen' or 'ladies'
102+Property CourseRating:Single
103+Property SlopeRating:Cardinal
93104
94-`// Hole Properties`\
95-`// Change Hole by changing the HoleIndex property (0-17)`\
96-`property HoleIndex:Cardinal //(zero-based)`\
97-`Property Par:Cardinal`\
98-`Property StrokeIndex:Cardinal`\
99-`Property Metric:Boolean // Affects Distance conversion. Metric=TRUE means distances in meters`\
100-`Property TeeDistanceMetres:Cardinal`\
101-`Property TeeDistanceYards:Cardinal`\
102-`// Note Tee Distances are automatically converted yards->meters and meters->yards.`\
103-`// Only specify yards OR meters when setting Tee Distances`\
105+// Hole Properties
106+// Change Hole by changing the HoleIndex property (0-17)
107+property HoleIndex:Cardinal //(zero-based)
108+Property Par:Cardinal
109+Property StrokeIndex:Cardinal
110+Property Metric:Boolean // Affects Distance conversion. Metric=TRUE means distances in meters
111+Property TeeDistanceMetres:Cardinal
112+Property TeeDistanceYards:Cardinal
113+// Note Tee Distances are automatically converted yards->meters and meters->yards.
114+// Only specify yards OR meters when setting Tee Distances
104115
105-`// Stylesheet writing properties`\
106-`Property IncludeScoreCardStylesheetReference:Boolean`\
107-`Property IncludePlayerScoreCardStylesheetReference:Boolean`\
108-`Property ScoreCardPlayerName:String`\
109-`Property ScoreCardPlayerGender:String`\
110-`Property ScoreCardPlayerDateOfBirth:String`\
111-`Property ScoreCardPlayerHandicap:Single`\
116+// Stylesheet writing properties
117+Property IncludeScoreCardStylesheetReference:Boolean
118+Property IncludePlayerScoreCardStylesheetReference:Boolean
119+Property ScoreCardPlayerName:String
120+Property ScoreCardPlayerGender:String
121+Property ScoreCardPlayerDateOfBirth:String
122+Property ScoreCardPlayerHandicap:Single
112123
113-`=== Properties Read Only ===`\
124+=== Properties Read Only ===
114125
115-`Property Version:String readonly;`\
116-`Property InTeeDistance:Cardinal; // Calculated value for each course.Metric determines metres or yards`\
117-`Property OutTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards`\
118-`Property TotalTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards`\
119-`Property CourseTotalPar:Cardinal // Calculated value for each course.`\
120-`Property BogeyRating:Single // Calculated value for each tee position.`\
121-`property MaxCourseIndex:Cardinal // Highest value for CourseIndex`\
122-`Property MaxTeeColourIndex:Cardinal`\
123-`Property ClubMaxAmenitiesIndex:Cardinal`\
124-`Property ClubMaxCommentsIndex:Cardinal`
126+Property Version:String readonly;
127+Property InTeeDistance:Cardinal; // Calculated value for each course.Metric determines metres or yards
128+Property OutTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards
129+Property TotalTeeDistance:Cardinal // Calculated value for each course. Metric determines metres or yards
130+Property CourseTotalPar:Cardinal // Calculated value for each course.
131+Property BogeyRating:Single // Calculated value for each tee position.
132+property MaxCourseIndex:Cardinal // Highest value for CourseIndex
133+Property MaxTeeColourIndex:Cardinal
134+Property ClubMaxAmenitiesIndex:Cardinal
135+Property ClubMaxCommentsIndex:Cardinal
136+```
125137
126138- MaxIndex-type properties help when setting up a loop to read the indexed property values e.g.
127139
128-`With GolfmlClass do`\
129-`  Begin`\
130-`    For iCount:=0 to MaxCourseIndex do`\
131-`     begin`\
132-`        CourseIndex:=iCount; // Set the course number`\
133-`        MyStringList.Add(CourseName); // Read data for this course`\
134-`    end;`\
135-`  End;`
140+``` pascal
141+With GolfmlClass do
142+ Begin
143+ For iCount:=0 to MaxCourseIndex do
144+ begin
145+ CourseIndex:=iCount; // Set the course number
146+ MyStringList.Add(CourseName); // Read data for this course
147+ end;
148+ End;
149+```
136150
137151------------------------------------------------------------------------
138152
139153SIMPLE WRITING EXAMPLE: To set the Par of Hole 3 to the value 5 on the first course at Tee-position 1:
140154
141-`GolfmlClass.CourseIndex:=0;`\
142-`GolfmlClass.TeeIndex:=0;`\
143-`GolfmlClass.HoleIndex:=2;`\
144-`GolfmlClass.Par:=5;`
155+``` pascal
156+GolfmlClass.CourseIndex:=0;
157+GolfmlClass.TeeIndex:=0;
158+GolfmlClass.HoleIndex:=2;
159+GolfmlClass.Par:=5;
160+```
145161
146162------------------------------------------------------------------------
147163
148164SIMPLE READING EXAMPLE: To get the Par of Hole 3 on the first course at Tee-position 1:
149165
150-`GolfmlClass.CourseIndex:=0;`\
151-`GolfmlClass.TeeIndex:=0;`\
152-`GolfmlClass.HoleIndex:=2;`\
153-`cParVariable:=GolfmlClass.Par;`
166+``` pascal
167+GolfmlClass.CourseIndex:=0;
168+GolfmlClass.TeeIndex:=0;
169+GolfmlClass.HoleIndex:=2;
170+cParVariable:=GolfmlClass.Par;
171+```
154172
155173------------------------------------------------------------------------
156174
157175#### How to populate the data before calling MakeGolfmlFile
158176
159177Normally you would set up 3 nested loops, and assign values to properties within the loops according to their scope.
160178
161179MULTIPLE WRITING EXAMPLE:
162180
163-`GolfmlClass.Reset;`\
164-`...Set Club-wide properties...`\
165-`For CourseLoop:=0 to ... DO`\
166-`  GolfmlClass.CourseIndex:=CourseLoop; // Write data to this course`\
167-`  ...assign Course-wide properties...`\
168-`  For TeeLoop:=0 to .. DO`\
169-`    GolfmlClass.TeeColourIndex:=TeeLoop; // Write data to this Tee Position in this course`\
170-`    ...assign Tee Position-wide properties...`\
171-`    For HoleLoop:=0 to 17 (or 9) DO`\
172-`        GolfmlClass.HoleIndex:=HoleLoop; // Write data to this hole in this Tee Position in this course`\
173-`        ...assign Hole properties....`\
174-`    end; // next hole`\
175-`  end; // next tee position`\
176-`end; // next course`\
177-`GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';`\
178-`GolfmlClass.MakeGolfmlFile;`
181+``` pascal
182+GolfmlClass.Reset;
183+...Set Club-wide properties...
184+For CourseLoop:=0 to ... DO
185+ GolfmlClass.CourseIndex:=CourseLoop; // Write data to this course
186+ ...assign Course-wide properties...
187+ For TeeLoop:=0 to .. DO
188+ GolfmlClass.TeeColourIndex:=TeeLoop; // Write data to this Tee Position in this course
189+ ...assign Tee Position-wide properties...
190+ For HoleLoop:=0 to 17 (or 9) DO
191+ GolfmlClass.HoleIndex:=HoleLoop; // Write data to this hole in this Tee Position in this course
192+ ...assign Hole properties....
193+ end; // next hole
194+ end; // next tee position
195+end; // next course
196+GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';
197+GolfmlClass.MakeGolfmlFile;
198+```
179199
180200------------------------------------------------------------------------
181201
182202#### How to retrieve the data after calling GetCourseInfoFromFile
183203
184204MULTIPLE READING EXAMPLE
185205
186-`GolfmlClass.Reset;`\
187-`GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';`\
188-`GolfmlClass.GetCourseInfoFromFile;`\
206+``` pascal
207+GolfmlClass.Reset;
208+GolfmlClass.CourseXMLPath:='C:\courses\mycourse.xml';
209+GolfmlClass.GetCourseInfoFromFile;
189210
190-`//Retrieve the Club properties first.`\
191-`sName:=GolfmlClass.Clubname;`\
192-`...etc`\
193-`//Now get all the Club Amenities via a loop.`
211+//Retrieve the Club properties first.
212+sName:=GolfmlClass.Clubname;
213+...etc
214+//Now get all the Club Amenities via a loop.
215+```
194216
195217*Remember the amenity type and description are separated by a comma*
196218
197219Here's a function to separate them
198220
199-`procedure SplitAmenety(var fAmenityType,fAmenetyValue:String;Const aString:String);`\
200-`// Changes fAmenityType, fAmenetyValue`\
201-`// Uses C_AMENETYDELIMITERCHAR`\
202-`Var`\
203-`   i:Integer;`\
204-`begin`\
205-`     if Length(aString)=0 then exit;`\
206-`     i:=Pos(C_AMENETYDELIMITERCHAR,aString);`\
207-`     If i > 1 then`\
208-`     Begin`\
209-`          fAmenityType:=LeftStr(aString,i-1);`\
210-`          fAmenetyValue:=RightStr(aString,Length(aString)-i);`\
211-`     end;`\
212-`end;`\
221+``` pascal
222+procedure SplitAmenety(var fAmenityType,fAmenetyValue:String;Const aString:String);
223+// Changes fAmenityType, fAmenetyValue
224+// Uses C_AMENETYDELIMITERCHAR
225+Var
226+ i:Integer;
227+begin
228+ if Length(aString)=0 then exit;
229+ i:=Pos(C_AMENETYDELIMITERCHAR,aString);
230+ If i > 1 then
231+ Begin
232+ fAmenityType:=LeftStr(aString,i-1);
233+ fAmenetyValue:=RightStr(aString,Length(aString)-i);
234+ end;
235+end;
213236
214-`Var sAmenityType, sAmenityValue:String;`\
215-`For iLoop:=0 to GolfmlClass.ClubMaxAmenitiesIndex do`\
216-`  begin`\
217-`       // Initialise strings to pass by value to procedure`\
218-`       sAmenityType:='';`\
219-`       sAmenityValue:='';    `
237+Var sAmenityType, sAmenityValue:String;
238+For iLoop:=0 to GolfmlClass.ClubMaxAmenitiesIndex do
239+ begin
240+ // Initialise strings to pass by value to procedure
241+ sAmenityType:='';
242+ sAmenityValue:='';
243+```
220244
221-`SplitAmenety(sAmenityType,sAmenityValue,GolfmlClass.ClubAmeneties[iLoop]);`\
222-`       MyAmenityTypeList.Add(sAmenityType);`\
223-`       MyAmenityValueList.Add(sAmenityValue);`\
224-`  End;`
245+``` pascal
246+SplitAmenety(sAmenityType,sAmenityValue,GolfmlClass.ClubAmeneties[iLoop]);
247+ MyAmenityTypeList.Add(sAmenityType);
248+ MyAmenityValueList.Add(sAmenityValue);
249+ End;
250+```
225251
226252... fetch the ClubComments in the same way...
227253
228-`For iLoop:=0 to GolfmlClass.ClubMaxCommentsIndex do`\
229-`  begin `\
230-`       MyStringList.Add(GolfmlClass.ClubComments[iLoop]);`\
231-`  End;`
254+``` pascal
255+For iLoop:=0 to GolfmlClass.ClubMaxCommentsIndex do
256+ begin
257+ MyStringList.Add(GolfmlClass.ClubComments[iLoop]);
258+ End;
259+```
232260
233261Retrieve the data for each hole in each tee set in each course via a loop
234262
235-`For CourseLoop:=0 to GolfmlClass.MaxCourseIndex DO`\
236-`  GolfmlClass.CourseIndex:=CourseLoop; // Read data from this course`\
237-`  ...get Course-wide properties...`\
238-`  .. get Hole pars and strokeindexes (via a holeindex loop)`\
239-`  For TeeLoop:=0 to GolfmlClass.MaxTeeColourIndex DO`\
240-`    GolfmlClass.TeeColourIndex:=TeeLoop; // Read data from this Tee Position in this course`\
241-`    ...get Tee Position-wide properties for this course`\
242-`    .... get Course and Slope ratings.  Get the Tee colours, titles and genders...`\
243-`    For HoleLoop:=GolfmlClass.CourseNumberOfHoles DO`\
244-`        GolfmlClass.HoleIndex:=HoleLoop; // Read data from this hole in this Tee Position in this course`\
245-`        GolfmlClass.Metric:=TRUE; //=FALSE would retrieve yards`\
246-`        ...Get Hole distances in metres`\
247-`    end; // next hole`\
248-`  end; // next tee position`\
249-`end; // next course`
263+``` pascal
264+For CourseLoop:=0 to GolfmlClass.MaxCourseIndex DO
265+ GolfmlClass.CourseIndex:=CourseLoop; // Read data from this course
266+ ...get Course-wide properties...
267+ .. get Hole pars and strokeindexes (via a holeindex loop)
268+ For TeeLoop:=0 to GolfmlClass.MaxTeeColourIndex DO
269+ GolfmlClass.TeeColourIndex:=TeeLoop; // Read data from this Tee Position in this course
270+ ...get Tee Position-wide properties for this course
271+ .... get Course and Slope ratings. Get the Tee colours, titles and genders...
272+ For HoleLoop:=GolfmlClass.CourseNumberOfHoles DO
273+ GolfmlClass.HoleIndex:=HoleLoop; // Read data from this hole in this Tee Position in this course
274+ GolfmlClass.Metric:=TRUE; //=FALSE would retrieve yards
275+ ...Get Hole distances in metres
276+ end; // next hole
277+ end; // next tee position
278+end; // next course
279+```
250280
251281## Summary
252282
253283Each property has a *scope* within a Club, Course, Tee-position or Hole.
254284
255285..for instance:
256286
257287- Distances are for a course, tee-position and hole
258288- StrokeIndexes are for a course and hole only.
259289- CourseRating is for a course and tee-position only
260290
261291GolfmlClass 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.
262292
263293---
264294*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).*
265295Category: Components
266296Category: XML

Back to history