mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-21 20:25:58 +02:00

sparta: initial commit of "compilable" new sparta package - smart form editor. !NOTE: not for daily usage. ........ sparta: Initial conception for package for MDI: sparta_MDI. Base for sparta_DockedFormEditor package. ........ sparta: Generics.Collections library ( sync with https://github.com/dathox/generics.collections SHA fda586932bd80ef58c08f8ebf5a24316ca4ccca5) ........ sparta: smart form editor adjustment for new sparta_MDI ........ sparta: new class "TFormImpl" for MDI solution (created from TDesignedFormImpl). ........ sparta: -MDI form container "TFormContainer" -New IResizeFrame interface to handle MDI form moving -New frame TfrFormBackgroundForMDI ........ sparta: sparta_MDI package modifications: -new class TMultiplyResizer to menage MDI desktop -more generic resizer: TAbstractResizer. Base for IDE resizer and TMultiplyResizer -more advanced IResizeFrame interface ........ sparta: -DockedFormEditor adjustment for latest changes in mdi package -small changes in mdi (visibility of methods). -OnModified method for IResizeFrame ........ sparta: MDI -simulate MDI forms order for TMultiplyResizer -property DesignedForm: IDesignedForm for IResizeFrame ........ sparta: -IMPORTANT! pixel perfect form resizing (fix for problems for controls with align alLeft, alRight etc on design form). -Fix problem for windows: wrong design design window width (a little bigger than designed size) TFormImpl.SetRealBounds -> AdjustSize ........ sparta: mdi bug fix for AV in TMultiplyResizer ........ Fix compilation for FPC 3.0 (TRect changes in FPC 3.1 trunk) ........ sparta: Cannot resize the docked form designer, issue #29380 patch from Anthony Walter. Thanks! ........ sparta ToolsAPI: Delphi compatible ToolsAPI/DesignIDE interface at XE2 level (proxy for IDEIntf). Initial commit (no functionality yet), just interfaces and classes without implementation: designeditors.pas: -TComponentEditor designintf.pas: -Interfaces: IEventInfo, IClass, IActivatable, IDesignObject, IDesignPersistent, IDesignerSelections, IDesigner60, IDesigner70, IDesigner80, IDesigner100, IDesigner, IComponentEditor -TBaseComponentEditor -RegisterComponentEditor designmenus.pas: -Interfaces: IMenuItems, IMenu, IMainMenu, IPopupMenu, IMenuItem ........ when form is removed we need to remove all handlers located in collections FFormsStack and FForms. Necessary to avoid AV. ........ sparta: more correct and simpler calculation of form border for Windows ........ sparta: * Fix for loop error for resize. Highly visible problem for docked forms/frames with Align=alClient. * New THookFrame class as new meta class for Frames. ........ updated lpl ........ git-svn-id: trunk@52728 -
125 lines
3.4 KiB
ObjectPascal
125 lines
3.4 KiB
ObjectPascal
// Generic types for FreeSparta.com and FreePascal!
|
|
// by Maciej Izak (hnb), 2014
|
|
|
|
program TComparerProject;
|
|
|
|
{$MODE DELPHI}
|
|
{$APPTYPE CONSOLE}
|
|
|
|
uses
|
|
SysUtils, Generics.Collections, Generics.Defaults;
|
|
|
|
type
|
|
|
|
{ TCustomer }
|
|
|
|
TCustomer = record
|
|
private
|
|
FName: string;
|
|
FMoney: Currency;
|
|
public
|
|
constructor Create(const Name: string; Money: Currency);
|
|
property Name: string read FName write FName;
|
|
property Money: Currency read FMoney write FMoney;
|
|
function ToString: string;
|
|
end;
|
|
|
|
TCustomerComparer = class(TComparer<TCustomer>)
|
|
function Compare(constref Left, Right: TCustomer): Integer; override;
|
|
end;
|
|
|
|
{ TCustomer }
|
|
|
|
constructor TCustomer.Create(const Name: string; Money: Currency);
|
|
begin
|
|
FName := Name;
|
|
FMoney := Money;
|
|
end;
|
|
|
|
function TCustomer.ToString: string;
|
|
begin
|
|
Result := Format('Name: %s >>> Money: %m', [Name, Money]);
|
|
end;
|
|
|
|
// Ascending
|
|
function TCustomerComparer.Compare(constref Left, Right: TCustomer): Integer;
|
|
begin
|
|
Result := TCompare.&String(Left.Name, Right.Name);
|
|
if Result = 0 then
|
|
Result := TCompare.Currency(Left.Money, Right.Money);
|
|
end;
|
|
|
|
// Descending
|
|
function CustomerCompare(constref Left, Right: TCustomer): Integer;
|
|
begin
|
|
Result := TCompare.&String(Right.Name, Left.Name);
|
|
if Result = 0 then
|
|
Result := TCompare.Currency(Right.Money, Left.Money);
|
|
end;
|
|
|
|
var
|
|
CustomersArray: TArray<TCustomer>;
|
|
CustomersList: TList<TCustomer>;
|
|
Comparer: TCustomerComparer;
|
|
Customer: TCustomer;
|
|
begin
|
|
CustomersArray := TArray<TCustomer>.Create(
|
|
TCustomer.Create('Derp', 2000),
|
|
TCustomer.Create('Sheikh', 2000000000),
|
|
TCustomer.Create('Derp', 1000),
|
|
TCustomer.Create('Bill Gates', 1000000000));
|
|
|
|
Comparer := TCustomerComparer.Create;
|
|
Comparer._AddRef;
|
|
|
|
// create TList with custom comparer
|
|
CustomersList := TList<TCustomer>.Create(Comparer);
|
|
CustomersList.AddRange(CustomersArray);
|
|
|
|
WriteLn('CustomersList before sort:');
|
|
for Customer in CustomersList do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
// default sort
|
|
CustomersList.Sort; // will use TCustomerComparer (passed in the constructor)
|
|
WriteLn('CustomersList after ascending sort (default with interface from constructor):');
|
|
for Customer in CustomersList do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
// construct with simple function
|
|
CustomersList.Sort(TComparer<TCustomer>.Construct(CustomerCompare));
|
|
WriteLn('CustomersList after descending sort (by using construct with function)');
|
|
WriteLn('CustomersList.Sort(TComparer<TCustomer>.Construct(CustomerCompare)):');
|
|
for Customer in CustomersList do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
// construct with method
|
|
CustomersList.Sort(TComparer<TCustomer>.Construct(Comparer.Compare));
|
|
WriteLn('CustomersList after ascending sort (by using construct with method)');
|
|
WriteLn('CustomersList.Sort(TComparer<TCustomer>.Construct(Comparer.Compare)):');
|
|
for Customer in CustomersList do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
WriteLn('CustomersArray before sort:');
|
|
for Customer in CustomersArray do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
// sort with interface
|
|
TArrayHelper<TCustomer>.Sort(CustomersArray, TCustomerComparer.Create);
|
|
WriteLn('CustomersArray after ascending sort (by using interfese - no construct)');
|
|
WriteLn('TArrayHelper<TCustomer>.Sort(CustomersArray, TCustomerComparer.Create):');
|
|
for Customer in CustomersArray do
|
|
WriteLn(Customer.ToString);
|
|
WriteLn;
|
|
|
|
CustomersList.Free;
|
|
Comparer._Release;
|
|
ReadLn;
|
|
end.
|
|
|