Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit5;
- interface
- uses
- MVCFramework, Spring, Spring.Collections;
- type
- [MVCPath('/')]
- TMyController = class(TMVCController)
- public
- [MVCPath('/')]
- [MVCHTTPMethod([httpGET])]
- procedure Index(ctx: TWebContext);
- procedure OnBeforeAction(Context: TWebContext; const AActionName: string;
- var Handled: Boolean); override;
- procedure OnAfterAction(Context: TWebContext;
- const AActionName: string); override;
- end;
- TPerson = class
- private
- FFirstName: String;
- FLastName: String;
- public
- constructor Create(aName, aLastName: String);
- property FirstName: String read FFirstName write FFirstName;
- property LastName: String read FLastName write FLastName;
- end;
- implementation
- uses
- System.Generics.Collections;
- procedure TMyController.Index(ctx: TWebContext);
- var
- lList: IList<TPerson>;
- lObjList: TObjectList<TPerson>;
- begin
- lList := TCollections.CreateObjectList<TPerson>;
- lList.Add(TPerson.Create('Daniele', 'Teti'));
- lList.Add(TPerson.Create('Peter', 'Parker'));
- lList.Add(TPerson.Create('Bruce', 'Banner'));
- //copy the references to a standard TObjectList<T>
- lObjList := TObjectList<TPerson>.Create(false);
- lObjList.AddRange(lList.ToArray);
- Render<TPerson>(lObjList);
- end;
- procedure TMyController.OnAfterAction(Context: TWebContext;
- const AActionName: string);
- begin
- { Executed after each action }
- inherited;
- end;
- procedure TMyController.OnBeforeAction(Context: TWebContext;
- const AActionName: string; var Handled: Boolean);
- begin
- { Executed before each action
- if handled is true (or an exception is raised) the actual
- action will not be called }
- inherited;
- end;
- { TPerson }
- constructor TPerson.Create(aName, aLastName: String);
- begin
- inherited Create;
- FirstName := aName;
- LastName := aLastName;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement