File: simplest_curve_read.lpr

package info (click to toggle)
castle-game-engine 6.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 194,520 kB
  • sloc: pascal: 364,585; ansic: 8,606; java: 2,851; objc: 2,601; cpp: 1,412; xml: 851; makefile: 725; sh: 563; php: 26
file content (29 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
uses SysUtils, CastleVectors, CastleFilesUtils, CastleCurves;
var
  FirstCurve: TCurve;
  Curves: TCurveList;
begin
  FirstCurve := TCurve.LoadFromFile(ApplicationData('my_curves.xml'));
  try
    // That's it, you loaded the 1st curve from XML file.
    // Write some initial curve points.
    Writeln(FirstCurve.Point(0.0).ToString);
    Writeln(FirstCurve.Point(0.1).ToString);
  finally FreeAndNil(FirstCurve) end;

  { in more complicated scenarios, my_curves.xml may keep many curves
    inside. Load them like this: }

  Curves := TCurveList.Create(true { free objects });
  try
    Curves.LoadFromFile(ApplicationData('my_curves.xml'));
    if Curves.Count = 0 then
      raise Exception.Create('No curves defined in file');
    FirstCurve := Curves[0];
    // That's it, you have the 1st curve from XML file.
    // Write some initial curve points.
    Writeln(FirstCurve.Point(0.0).ToString);
    Writeln(FirstCurve.Point(0.1).ToString);
    Writeln(FirstCurve.Point(0.2).ToString);
  finally FreeAndNil(Curves) end;
end.