summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-db/examples/dbftool.lpr
blob: df8f087ce70f4b09992716a60cc64c5eef7723f1 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
program dbftool;

{ Reads and exports DBF files. Can create a demo DBF file to test with.

Demonstrates creating DBF tables, filling it with data,
and exporting datasets.
}

{$mode objfpc}{$H+}

uses {$IFDEF UNIX} {$IFDEF UseCThreads}
  cthreads, {$ENDIF} {$ENDIF}
  Classes,
  SysUtils,
  CustApp,
  DB,
  dbf,
  dbf_fields,
  dbf_common,
  dateutils,
  fpdbexport,
  fpcsvexport,
  fpdbfexport,
  fpfixedexport,
  fprtfexport,
  fpsimplejsonexport,
  fpsimplexmlexport,
  fpsqlexport,
  fptexexport,
  fpxmlxsdexport;


type

  { TDBFTool }

  TDBFTool = class(TCustomApplication)
  private
    procedure ExportDBF(var MyDbf: TDbf);
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHelp; virtual;
  end;

  procedure CreateDemoDBFs(Directory: string; TableLevel: integer);
  // Creates 2 demonstration DBFs in Directory with dbase compatibility level
  // TableLevel
  // and specified codepage (if not CODEPAGE_NOT_SPECIFIED)
  var
    NewDBF: TDBF;
    i: integer;
  begin

    NewDBF := TDBF.Create(nil);
    try
      if Directory = '' then
        NewDBF.FilePath := '' { application directory}
      else
        NewDBF.FilePathFull := ExpandFileName(Directory) {full absolute path};
      if TableLevel <= 0 then
        NewDBF.TableLevel := 4 {default to DBase IV}
      else
        NewDBF.TableLevel := TableLevel;

      NewDBF.TableName := 'CUSTOMER.DBF';
      writeln('Creating ', NewDBF.TableName, ' with table level ', NewDBF.TableLevel);
      if TableLevel >= 30 then
      begin
        NewDBF.FieldDefs.Add('CUST_NO', ftAutoInc);
      end
      else
        NewDBF.FieldDefs.Add('CUST_NO', ftInteger);
      NewDBF.FieldDefs.Add('CUSTOMER', ftString, 25);
      NewDBF.FieldDefs.Add('CITY', ftString, 25);
      NewDBF.FieldDefs.Add('COUNTRY', ftString, 15);
      NewDBF.CreateTable;
      NewDBF.Open;

      for i := 1 to 5 do //keep size manageable until we have working files
      begin
        NewDBF.Append;
        if (NewDBF.FieldDefs.Find('CUST_NO').DataType <> ftAutoInc) then
          NewDBF.FieldByName('CUST_NO').AsInteger := i;
        case i of
          1:
          begin
            NewDBF.FieldByName('CUSTOMER').AsString := 'Michael Design';
            NewDBF.FieldByName('CITY').AsString := 'San Diego';
            NewDBF.FieldByName('COUNTRY').AsString := 'USA';
          end;
          2:
          begin
            NewDBF.FieldByName('CUSTOMER').AsString := 'Michael Design';
            NewDBF.FieldByName('CITY').AsString := 'San Diego';
            NewDBF.FieldByName('COUNTRY').AsString := 'USA';
          end;
          3:
          begin
            NewDBF.FieldByName('CUSTOMER').AsString := 'VC Technologies';
            NewDBF.FieldByName('CITY').AsString := 'Dallas';
            NewDBF.FieldByName('COUNTRY').AsString := 'USA';
          end;
          4:
          begin
            NewDBF.FieldByName('CUSTOMER').AsString := 'Klämpfl, Van Canneyt';
            NewDBF.FieldByName('CITY').AsString := 'Boston';
            NewDBF.FieldByName('COUNTRY').AsString := 'USA';
          end;
          5:
          begin
            NewDBF.FieldByName('CUSTOMER').AsString := 'Felipe Bank';
            NewDBF.FieldByName('CITY').AsString := 'Manchester';
            NewDBF.FieldByName('COUNTRY').AsString := 'England';
          end;
        end;
        NewDBF.Post;
      end;
      NewDBF.Close;
    finally
      NewDBF.Free;
    end;

    NewDBF := TDBF.Create(nil);
    try
      if Directory = '' then
        NewDBF.FilePath := '' { application directory}
      else
        NewDBF.FilePathFull := ExpandFileName(Directory) {full absolute path};
      if TableLevel <= 0 then
        NewDBF.TableLevel := 4 {default to DBase IV}
      else
        NewDBF.TableLevel := TableLevel;

      NewDBF.TableName := 'EMPLOYEE.DBF';
      writeln('Creating ', NewDBF.TableName, ' with table level ', NewDBF.TableLevel);
      if TableLevel >= 30 then
      begin
        NewDBF.FieldDefs.Add('EMP_NO', ftAutoInc);
      end
      else
        NewDBF.FieldDefs.Add('EMP_NO', ftInteger);
      NewDBF.FieldDefs.Add('FIRST_NAME', ftString, 15);
      NewDBF.FieldDefs.Add('LAST_NAME', ftString, 20);
      NewDBF.FieldDefs.Add('PHONE_EXT', ftString, 4);
      NewDBF.FieldDefs.Add('JOB_CODE', ftString, 5);
      NewDBF.FieldDefs.Add('JOB_GRADE', ftInteger);
      NewDBF.FieldDefs.Add('JOB_COUNTR', ftString, 15); //Note 10 character limit for table/field names in most DBases
      NewDBF.FieldDefs.Add('SALARY', ftFloat);
      NewDBF.CreateTable;
      NewDBF.Open;

      for i := 1 to 5 do //keep size manageable until we have working files
      begin
        NewDBF.Append;
        if (NewDBF.FieldDefs.Find('EMP_NO').DataType <> ftAutoInc) then
          NewDBF.FieldByName('EMP_NO').AsInteger := i;
        case i of
          1:
          begin
            NewDBF.FieldByName('FIRST_NAME').AsString := 'William';
            NewDBF.FieldByName('LAST_NAME').AsString := 'Shatner';
            NewDBF.FieldByName('PHONE_EXT').AsString := '1702';
            NewDBF.FieldByName('JOB_CODE').AsString := 'CEO';
            NewDBF.FieldByName('JOB_GRADE').AsInteger := 1;
            NewDBF.FieldByName('JOB_COUNTR').AsString := 'USA';
            NewDBF.FieldByName('SALARY').AsFloat := 48000;
          end;
          2:
          begin
            NewDBF.FieldByName('FIRST_NAME').AsString := 'Ivan';
            NewDBF.FieldByName('LAST_NAME').AsString := 'Ishenin';
            NewDBF.FieldByName('PHONE_EXT').AsString := '9802';
            NewDBF.FieldByName('JOB_CODE').AsString := 'Eng';
            NewDBF.FieldByName('JOB_GRADE').AsInteger := 2;
            NewDBF.FieldByName('JOB_COUNTR').AsString := 'Russia';
            NewDBF.FieldByName('SALARY').AsFloat := 38000;
          end;
          3:
          begin
            NewDBF.FieldByName('FIRST_NAME').AsString := 'Erin';
            NewDBF.FieldByName('LAST_NAME').AsString := 'Powell';
            NewDBF.FieldByName('PHONE_EXT').AsString := '1703';
            NewDBF.FieldByName('JOB_CODE').AsString := 'Admin';
            NewDBF.FieldByName('JOB_GRADE').AsInteger := 2;
            NewDBF.FieldByName('JOB_COUNTR').AsString := 'USA';
            NewDBF.FieldByName('SALARY').AsFloat := 45368;
          end;
          4:
          begin
            NewDBF.FieldByName('FIRST_NAME').AsString := 'Margaret';
            NewDBF.FieldByName('LAST_NAME').AsString := 'Tetchy';
            NewDBF.FieldByName('PHONE_EXT').AsString := '3804';
            NewDBF.FieldByName('JOB_CODE').AsString := 'Eng';
            NewDBF.FieldByName('JOB_GRADE').AsInteger := 3;
            NewDBF.FieldByName('JOB_COUNTR').AsString := 'England';
            NewDBF.FieldByName('SALARY').AsFloat := 28045;
          end;
          5:
          begin
            NewDBF.FieldByName('FIRST_NAME').AsString := 'Sergey';
            NewDBF.FieldByName('LAST_NAME').AsString := 'Bron';
            NewDBF.FieldByName('PHONE_EXT').AsString := '3807';
            NewDBF.FieldByName('JOB_CODE').AsString := 'Admin';
            NewDBF.FieldByName('JOB_GRADE').AsInteger := 3;
            NewDBF.FieldByName('JOB_COUNTR').AsString := 'England';
            NewDBF.FieldByName('SALARY').AsFloat := 24468;
          end;
        end;
        NewDBF.Post;
      end;
      NewDBF.Close;
    finally
      NewDBF.Free;
    end;
  end;

  procedure GetDBFList(Results: TStringList);
  // Gets list of all .dbf files in a directory and its subdirectories.
  var
    r: TSearchRec;
  begin
    results.Clear;
    if FindFirst('*.dbf', faAnyFile -
{$WARNINGS OFF}
      faVolumeID - faSymLink
{$WARNINGS ON}
      , r) = 0 then
    begin
      repeat
        if (r.Attr and faDirectory) <> faDirectory then
        begin
          results.add(expandfilename(r.Name));
        end;
      until (FindNext(r) <> 0);
      findclose(r);
    end;
  end;

  function BinFieldToHex(BinarySource: TField): string;
    // Convert binary field contents to strings with hexadecimal representation.
    // Useful for displaying binary field contents.
  var
    HexValue: PChar;
  begin
    Result := '';
    HexValue := StrAlloc(Length(BinarySource.AsBytes));
    try
      try
        BinToHex(PChar(BinarySource.AsBytes), HexValue, Length(BinarySource.AsBytes));
        Result := 'size: ' + IntToStr(Length(BinarySource.AsBytes)) + '; hex: ' + HexValue;
      except
        on E: Exception do
        begin
          Result := 'exception: ' + E.ClassName + '/' + E.Message;
        end;
      end;
    finally
      StrDispose(HexValue);
    end;
  end;

  procedure PrintRecord(DBf: TDBf; RecordNumber: integer);
  // Prints contents of a record to screen
  var
    i: integer;
  begin
    writeln('Record ' + IntToStr(RecordNumber));
    for i := 0 to DBf.Fields.Count - 1 do
    begin
      if DBF.fields[i].IsNull then
        writeln('Field ', DBf.Fields[i].FieldName, ' is          ***NULL***')
      else
      if DBF.Fields[i].DataType in [ftVarBytes, ftBytes] then
        writeln('Field ', DBF.Fields[i].FieldName, ' has value: binary ' + BinFieldToHex(DBF.Fields[i]))
      else
        writeln('Field ', DBf.Fields[i].FieldName, ' has value: ' + DBf.fields[i].AsString);
    end;
  end;

  { TDBFTool }

  procedure TDBFTool.ExportDBF(var MyDbf: TDbf);
  // Exports recordset to another format depending on user selection
  var
    ExportFormatText: string;
    ExportSettings: TCustomExportFormatSettings;
    Exporter: TCustomFileExporter;
  begin
    ExportFormatText := UpperCase(GetOptionValue('exportformat'));
    try
      case ExportFormatText of
        'ACCESS', 'MSACCESS':
        begin
          Exporter := TXMLXSDExporter.Create(nil);
          ExportSettings := TXMLXSDFormatSettings.Create(true);
          (ExportSettings as TXMLXSDFormatSettings).CreateXSD := true;
          (ExportSettings as TXMLXSDFormatSettings).ExportFormat :=
            AccessCompatible;
          (ExportSettings as TXMLXSDFormatSettings).DecimalSeparator := '.';
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.xml');
        end;
        'ADO', 'ADONET', 'ADO.NET':
        begin
          Exporter := TXMLXSDExporter.Create(nil);
          ExportSettings := TXMLXSDFormatSettings.Create(true);
          (ExportSettings as TXMLXSDFormatSettings).CreateXSD := true;
          (ExportSettings as TXMLXSDFormatSettings).ExportFormat :=
            ADONETCompatible;
          (ExportSettings as TXMLXSDFormatSettings).DecimalSeparator := '.';
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.xml');
        end;
        'CSVEXCEL', 'EXCELCSV', 'CREATIVYST':
        begin
          Exporter := TCSVExporter.Create(nil);
          ExportSettings := TCSVFormatSettings.Create(true);
          (ExportSettings as TCSVFormatSettings).RowDelimiter:=LineEnding;
          //todo: delimiter?
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.csv');
        end;
        'CSV', 'CSVRFC4180', 'CSVLIBRE', 'CSVLIBREOFFICE':
        begin
          Exporter := TCSVExporter.Create(nil);
          ExportSettings := TCSVFormatSettings.Create(true);
          (ExportSettings as TCSVFormatSettings).DecimalSeparator := '.';
          (ExportSettings as TCSVFormatSettings).StringQuoteChar := '"';
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.csv');
        end;
        'DATASET', 'DELPHI':
        begin
          Exporter := TXMLXSDExporter.Create(nil);
          ExportSettings := TXMLXSDFormatSettings.Create(true);
          (ExportSettings as TXMLXSDFormatSettings).ExportFormat :=
            DelphiClientDataset;
          (ExportSettings as TXMLXSDFormatSettings).DecimalSeparator := '.';
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.xml');
        end;
        'EXCEL', 'EXCELXML':
        begin
          Exporter := TXMLXSDExporter.Create(nil);
          ExportSettings := TXMLXSDFormatSettings.Create(true);
          (ExportSettings as TXMLXSDFormatSettings).ExportFormat := ExcelCompatible;
          (ExportSettings as TXMLXSDFormatSettings).DecimalSeparator := '.';
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.xml');
        end;
        'JSON':
        begin
          Exporter := TSimpleJSONExporter.Create(nil);
          ExportSettings := TSimpleJSONFormatSettings.Create(true);
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.json');
        end;
        'SIMPLEXML', 'XML':
        begin
          Exporter := TSimpleXMLExporter.Create(nil);
          ExportSettings := TSimpleXMLFormatSettings.Create(true);
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.xml');
        end;
        'RTF':
        begin
          Exporter := TRTFExporter.Create(nil);
          ExportSettings := TSimpleXMLFormatSettings.Create(true);
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.rtf');
        end;
        'SQL':
        begin
          Exporter := TSQLExporter.Create(nil);
          ExportSettings := TSQLFormatSettings.Create(true);
          (ExportSettings as TSQLFormatSettings).QuoteChar := '"';
          (ExportSettings as TSQLFormatSettings).DecimalSeparator := '.';
          (ExportSettings as TSQLFormatSettings).TableName := ChangeFileExt(MyDBF.TableName,'');
          (ExportSettings as TSQLFormatSettings).DateFormat := 'yyyy"-"mm"-"dd'; //ISO 8601, yyyy-mm-dd
          (ExportSettings as TSQLFormatSettings).TimeFormat := 'hh":"nn":"ss';   //ISO 8601, hh:mm:ss;
          (ExportSettings as TSQLFormatSettings).DateTimeFormat :=
            (ExportSettings as TSQLFormatSettings).DateFormat + '"T"' + (ExportSettings as TSQLFormatSettings).TimeFormat; //ISO 8601
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.sql');
        end;
        'TEX', 'LATEX':
        begin
          Exporter := TTeXExporter.Create(nil);
          ExportSettings := TTeXExportFormatSettings.Create(true);
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.tex');
        end;
        'TEXT', 'FIXED', 'FIXEDTEXT':
        begin
          Exporter := TFixedLengthExporter.Create(nil);
          ExportSettings := nil;
          Exporter.FileName := MyDBF.FilePathFull + ChangeFileExt(MyDBF.TableName, '.txt');
        end
        else
        begin
          writeln('***Error: Unknown export format ' + ExportFormatText + ' specified' + '. Aborting');
          Exporter := nil;
          ExportSettings := nil;
          Terminate;
          Exit;
        end;
      end;
      if assigned(ExportSettings) then
        Exporter.FormatSettings := ExportSettings;
      Exporter.Dataset := MyDBF;
      MyDBF.First; // we've just read the last record - make sure export starts at beginning
      Exporter.Execute;
      writeln('Completed export to ' + Exporter.FileName);
    finally
      if assigned(Exporter) then
        Exporter.Free;
      if assigned(ExportSettings) then
        ExportSettings.Free;
    end;
  end;

  procedure TDBFTool.DoRun;
  var
    DBFs: TStringList;
    Demo: boolean;
    ErrorMsg: string;
    FileNo: integer;
    MyDbf: TDbf;
    RecCount: integer;
    TableLevel: integer; //todo: use it
  begin
    // quick check parameters
    ErrorMsg := CheckOptions('h', 'codepage: createdemo exportformat: help tablelevel:');
    if ErrorMsg <> '' then
    begin
      ShowException(Exception.Create(ErrorMsg));
      Terminate;
      Exit;
    end;

    // parse parameters
    if HasOption('h', 'help') then
    begin
      WriteHelp;
      Terminate;
      Exit;
    end;

    DBFs := TStringList.Create;
    try
      Demo := false;
      if HasOption('createdemo') then
        Demo := true;

      TableLevel := 4; //DBF
      if HasOption('tablelevel') then
        TableLevel := StrToIntDef(GetOptionValue('tablelevel'), 4);

      if Demo then
      begin
        try
          CreateDemoDBFs('', TableLevel);
        except
          on E: Exception do
          begin
            writeln('*** Error creating demo databases: ' + E.Message);
            Terminate;
            Exit;
          end;
        end;
      end;

      // Process all dbfs if no files specified
      if DBFs.Count = 0 then
        GetDBFList(DBFs);

      if DBFs.Count = 0 then
        writeln('Could not find any dbf files');

      for FileNo := 0 to DBFs.Count - 1 do
      begin
        if not (fileexists(DBFs[FileNo])) then
        begin
          // for some reason, fpc trunk suddenly returns the directory as well...
          //writeln('Sorry, file ',DBFs[FileNo],' does not exist.');
          break;
        end;
        MyDbf := TDbf.Create(nil);
        try
          try
            MyDbf.FilePath := ExtractFilePath(DBFs[FileNo]);
            MyDbf.TableName := ExtractFileName(DBFs[FileNo]);
            MyDbf.ReadOnly := true;
            writeln('*** Opening: ' + DBFs[FileNo]);
            MyDbf.Open;
            writeln('Database tablelevel: ' + IntToStr(MyDbf.TableLevel));
            writeln('Database codepage:   ' + IntToStr(MyDBF.CodePage));

            RecCount := 1;
            while not (MyDbf.EOF) do
            begin
              PrintRecord(MyDBF, RecCount);
              MyDBF.Next;
              RecCount := RecCount + 1;
              writeln('');
            end;

            if HasOption('exportformat') then
            begin
              try
                ExportDBF(MyDbf);
              except
                on E: Exception do
                begin
                  writeln('*** Problem exporting file ', FileNo, ': ', E.Message);
                end;
              end;
            end;

            MyDbf.Close;
          except
            on E: Exception do
            begin
              writeln('*** Error reading file ', FileNo, ': ', E.Message);
            end;
          end;
        finally
          MyDbf.Free;
        end;
      end;
    finally
      DBFs.Free;
    end;

    // stop program loop
    Terminate;
  end;

  constructor TDBFTool.Create(TheOwner: TComponent);
  begin
    inherited Create(TheOwner);
    StopOnException := true;
  end;

  destructor TDBFTool.Destroy;
  begin
    inherited Destroy;
  end;

  procedure TDBFTool.WriteHelp;
  begin
    writeln('Usage: ', ExeName, ' -h');
    writeln(' --createdemo          create demo database');
    writeln(' --tablelevel=<n>      optional: desired tablelevel for demo db');
    writeln('  3                    DBase III');
    writeln('  4                    DBase IV');
    writeln('  7                    Visual DBase 7');
    writeln(' 25                    FoxPro 2.x');
    writeln(' 30                    Visual FoxPro');
    writeln(' --exportformat=<text> export dbfs to format. Format can be:');
    writeln(' access                Microsoft Access XML');
    writeln(' adonet                ADO.Net dataset');
    writeln(' csvexcel              Excel/Creativyst format CSV text file (with locale dependent output)');
    writeln(' csvRFC4180            LibreOffice/RFC4180 format CSV text file');
    writeln(' dataset               Delphi dataset XML');
    writeln(' excel                 Microsoft Excel XML');
    writeln(' fixedtext             Fixed length text file');
    writeln(' json                  JSON file');
    writeln(' rtf                   Rich Text Format');
    writeln(' simplexml             Simple XML');
    writeln(' sql                   SQL insert statements');
    writeln(' tex                   LaTeX file');
  end;

var
  Application: TDBFTool;
begin
  Application := TDBFTool.Create(nil);
  Application.Title := 'DBFTool';
  Application.Run;
  Application.Free;
end.