Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.80 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Dialogs, StdCtrls, Brook.Rtti, Brook.ListAdapters,
  9.   Brook.IO, Brook.Lexer, Brook.Parser;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   end;
  19.  
  20. {$M+}
  21.  
  22.   { TQuery }
  23.  
  24.   TQuery = class(TObject)
  25.   private
  26.     FFields: TStrings;
  27.   public
  28.     constructor Create;
  29.     destructor Destroy; override;
  30.   published
  31.     property Fields: TStrings read FFields write FFields;
  32.   end;
  33.  
  34. {$M-}
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. procedure TForm1.Button1Click(Sender: TObject);
  46. const
  47.   QS = 'fields[0]=f1value&fields[1]=f2value';
  48. var
  49.   q: string;
  50.   i: Integer;
  51.   query: TQuery;
  52.   converter: TBrookRttiConverter;
  53.   listadapter: TBrookListAdapters;
  54.   reader: TBrookTextReader;
  55.   lexer: TBrookLexer;
  56.   parser: TBrookParser;
  57. begin
  58.   q := StringReplace(QS, '&', sLineBreak, [rfReplaceAll]);
  59.  
  60.   query := TQuery.Create;
  61.   converter := TBrookRttiPropertyConverter.Create(query);
  62.   listadapter := TBrookListAdapters.Create;
  63.   reader := TBrookStringReader.Create(q);
  64.   lexer := TBrookPropertyLexer.Create(reader);
  65.   parser := TBrookPropertyParser.Create(lexer, converter, listadapter, query);
  66.   try
  67.     listadapter.Add(TBrookStringListAdapter.Create, [TStringList]);
  68.  
  69.     parser.Parse;
  70.  
  71.     // print
  72.     for i := 0 to Pred(query.Fields.Count) do
  73.       ShowMessageFmt('%s', [query.Fields[i]]);
  74.   finally
  75.     reader.Free;
  76.     lexer.Free;
  77.     listadapter.Free;
  78.     converter.Free;
  79.     parser.Free;
  80.     query.Free;
  81.   end;
  82. end;
  83.  
  84. { TQuery }
  85.  
  86. constructor TQuery.Create;
  87. begin
  88.   inherited Create;
  89.   FFields := TStringList.Create;
  90. end;
  91.  
  92. destructor TQuery.Destroy;
  93. begin
  94.   FFields.Free;
  95.   inherited Destroy;
  96. end;
  97.  
  98. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement