unit colourhistory; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls; type TColourPickerObject = class(TObject) constructor Create(C: Integer; P: TPoint; N: String); destructor Destroy; override; public Colour: Integer; Pos: TPoint; Name: String; end; { TColourHistoryForm } TColourHistoryForm = class(TForm) PickNewColourButton: TButton; DeleteButton: TButton; ColourValue: TLabel; CoordValue: TLabel; ColourList: TListView; SelectionName: TEdit; procedure ChangeName(Sender: TObject); procedure ChangeViewData(Sender: TObject; Item: TListItem; Selected: Boolean ); procedure DeleteSelected(Sender: TObject); procedure AddColObj(c: TColourPickerObject); constructor Create(TheOwner: TComponent); override; destructor Destroy; override; private { private declarations } public IndexSelected: Integer; { public declarations } end; var ColourHistoryForm: TColourHistoryForm; implementation uses TestUnit; constructor TColourPickerObject.Create(C: Integer; P: TPoint; N: String); begin inherited Create; Self.Colour := C; Self.Pos := P; Self.Name:= N; end; destructor TColourPickerObject.Destroy; begin inherited Destroy; end; { TColourHistoryForm } procedure TColourHistoryForm.AddColObj(c: TColourPickerObject); var it: TListItem; begin it := ColourList.Items.Add; it.Data := c; it.Caption:= c.Name; ColourList.Selected := it; end; procedure TColourHistoryForm.DeleteSelected(Sender: TObject); begin if (Assigned(ColourList.Selected)) then begin TColourPickerObject(ColourList.Selected.Data).Free; ColourList.Selected.Delete; end; end; procedure TColourHistoryForm.ChangeViewData(Sender: TObject; Item: TListItem; Selected: Boolean); begin ColourValue.Caption := 'Colour: ' + IntToStr(TColourPickerObject(ColourList.Selected.Data).Colour); CoordValue.Caption := 'Coords: ' + IntToStr(TColourPickerObject(ColourList.Selected.Data).Pos.X) + ', ' + IntToStr(TColourPickerObject(ColourList.Selected.Data).Pos.Y); SelectionName.Text := TColourPickerObject(ColourList.Selected.Data).Name; end; procedure TColourHistoryForm.ChangeName(Sender: TObject); begin if not Assigned(ColourList.Selected) then begin WriteLn('We double clicked but have nothing Selected?'); exit; end; ColourList.Selected.Caption := SelectionName.Text; TColourPickerObject(ColourList.Selected.Data).Name := SelectionName.Text; end; constructor TColourHistoryForm.Create(TheOwner: TComponent); begin inherited Create(TheOwner); PickNewColourButton.OnClick:= @Form1.ButtonPickClick; end; destructor TColourHistoryForm.Destroy; begin inherited Destroy; end; initialization {$I colourhistory.lrs} end.