Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, Forms, Dialogs, StdCtrls, Brook.Rtti, Brook.ListAdapters,
- Brook.IO, Brook.Lexer, Brook.Parser;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- end;
- {$M+}
- { TQuery }
- TQuery = class(TObject)
- private
- FFields: TStrings;
- public
- constructor Create;
- destructor Destroy; override;
- published
- property Fields: TStrings read FFields write FFields;
- end;
- {$M-}
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.Button1Click(Sender: TObject);
- const
- QS = 'fields[0]=f1value&fields[1]=f2value';
- var
- q: string;
- i: Integer;
- query: TQuery;
- converter: TBrookRttiConverter;
- listadapter: TBrookListAdapters;
- reader: TBrookTextReader;
- lexer: TBrookLexer;
- parser: TBrookParser;
- begin
- q := StringReplace(QS, '&', sLineBreak, [rfReplaceAll]);
- query := TQuery.Create;
- converter := TBrookRttiPropertyConverter.Create(query);
- listadapter := TBrookListAdapters.Create;
- reader := TBrookStringReader.Create(q);
- lexer := TBrookPropertyLexer.Create(reader);
- parser := TBrookPropertyParser.Create(lexer, converter, listadapter, query);
- try
- listadapter.Add(TBrookStringListAdapter.Create, [TStringList]);
- parser.Parse;
- // print
- for i := 0 to Pred(query.Fields.Count) do
- ShowMessageFmt('%s', [query.Fields[i]]);
- finally
- reader.Free;
- lexer.Free;
- listadapter.Free;
- converter.Free;
- parser.Free;
- query.Free;
- end;
- end;
- { TQuery }
- constructor TQuery.Create;
- begin
- inherited Create;
- FFields := TStringList.Create;
- end;
- destructor TQuery.Destroy;
- begin
- FFields.Free;
- inherited Destroy;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement