diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-10-12 09:14:22 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-10-12 09:14:22 +0200 |
commit | a8051f82e0d714d9bb20e92c29d45e8857217597 (patch) | |
tree | 7bb4a7fb6dfdf3de12c762a2289703d43f560fa3 /src | |
parent | 65b0e8c3546b2df6fb5ccab7addfeabd5ac4e2e6 (diff) | |
download | fpGUI-a8051f82e0d714d9bb20e92c29d45e8857217597.tar.xz |
listbox: Text property is now a read/write property
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/fpg_listbox.pas | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/gui/fpg_listbox.pas b/src/gui/fpg_listbox.pas index 1b5c897b..68f15080 100644 --- a/src/gui/fpg_listbox.pas +++ b/src/gui/fpg_listbox.pas @@ -117,6 +117,8 @@ type TfpgTextListBox = class(TfpgBaseListBox) protected FItems: TStringList; + function GetText: string; virtual; + procedure SetText(const AValue: string); virtual; procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); override; procedure Exchange(Index1, Index2: Integer); override; procedure HandleKeyChar(var AText: TfpgChar; var shiftstate: TShiftState; var consumed: boolean); override; @@ -125,7 +127,7 @@ type constructor Create(AOwner: TComponent); override; destructor Destroy; override; function ItemCount: integer; override; - function Text: string; + property Text: string read GetText write SetText stored False; end; @@ -859,6 +861,35 @@ end; { TfpgTextListBox } +function TfpgTextListBox.GetText: string; +begin + if (ItemCount > 0) and (FocusItem <> -1) then + result := FItems[FocusItem] + else + result := ''; +end; + +procedure TfpgTextListBox.SetText(const AValue: string); +var + i: integer; +begin + if AValue = '' then + SetFocusItem(-1) // nothing selected + else + begin + for i := 0 to FItems.Count-1 do + begin + if SameText(Items.Strings[i], AValue) then + begin + SetFocusItem(i); + Exit; //==> + end; + end; + // if we get here, we didn't find a match + SetFocusItem(-1); + end; +end; + procedure TfpgTextListBox.DrawItem(num: integer; rect: TfpgRect; flags: integer); begin //if num < 0 then @@ -909,14 +940,6 @@ begin result := FItems.Count; end; -function TfpgTextListBox.Text: string; -begin - if (ItemCount > 0) and (FocusItem <> -1) then - result := FItems[FocusItem] - else - result := ''; -end; - { TColorItem } constructor TColorItem.Create (const AColorName: string; const AColorValue: TfpgColor); |