[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Items property. I want to remove the listboxes off my screen to save resources.

In my application I have alot of listboxes because it has the Items property and alot of my code referred to Items Property.
Is there any class that I can instantiate and that has access to the Items property.

The TStrings and the TStringList classes do not have the Items property.
I dont like to have alot of listboxes on my screen.

What do you suggest? Will removing the listboxes off my screen save resources?

Ben

0
Alpha_AI
Asked:
Alpha_AI
  • 3
2 Solutions
 
diniludCommented:
See the type of ListBox's item property.It is TStrings.
So You can use TStringList to store your item property
0
 
diniludCommented:
if you wand as component then try this

unit MyItem;

interface

uses
  SysUtils, Classes;

type
  TMyItem = class(TComponent)
  private
    { Private declarations }
    FItem:TStringList;
    procedure SetItem(Value:TStrings);
    function GetItem:TStrings;
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Public declarations }

  published
    { Published declarations }
    property Item:TStrings read GetItem write SetItem;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyItem]);
end;

constructor TMyItem.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FItem:=TStringList.Create;
end;

destructor TMyItem.Destroy;
begin
  FItem.Free;
  Inherited Destroy;
end;


procedure TMyItem.SetItem(Value:TStrings);
begin
  FItem.Assign(Value);
end;

function TMyItem.GetItem:TStrings;
begin
  Result:=FItem;
end;

end.
0
 
diniludCommented:
Simple Class
=============


  TMyItemClass = class
  private
    FItem:TStringList;
    procedure SetItem(Value:TStrings);
    function GetItem:TStrings;
  public
    constructor Create;
    destructor Destroy; override;
    property Item:TStrings read GetItem write SetItem;
  end;


...................
...................




constructor TMyItemClass.Create;
begin
  inherited Create;
  FItem:=TStringList.Create;
end;

destructor TMyItemClass.Destroy;
begin
  FItem.Free;
  Inherited Destroy;
end;


procedure TMyItemClass.SetItem(Value:TStrings);
begin
  FItem.Assign(Value);
end;

function TMyItemClass.GetItem:TStrings;
begin
  Result:=FItem;
end;
0
 
MerijnBSr. Software EngineerCommented:
you migh want to rename the property 'Item' to 'Items' to make 'perfect copy':


unit MyItems;

interface

uses
  SysUtils, Classes;

type
  TMyItems = class(TComponent)
  private
    { Private declarations }
    FItems:TStringList;
    procedure SetItems(Value:TStrings);
    function GetItems:TStrings;
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Public declarations }

  published
    { Published declarations }
    property Items:TStrings read GetItems write SetItems;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyItems]);
end;

constructor TMyItems.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FItems:=TStringList.Create;
end;

destructor TMyItems.Destroy;
begin
  FItems.Free;
  Inherited Destroy;
end;


procedure TMyItems.SetItems(Value:TStrings);
begin
  FItems.Assign(Value);
end;

function TMyItems.GetItems:TStrings;
begin
  Result:=FItems;
end;

end.



Simple Class
=============


  TMyItemsClass = class
  private
    FItems:TStringList;
    procedure SetItems(Value:TStrings);
    function GetItems:TStrings;
  public
    constructor Create;
    destructor Destroy; override;
    property Items:TStrings read GetItems write SetItems;
  end;


...................
...................




constructor TMyItemsClass.Create;
begin
  inherited Create;
  FItems:=TStringList.Create;
end;

destructor TMyItemsClass.Destroy;
begin
  FItems.Free;
  Inherited Destroy;
end;


procedure TMyItemsClass.SetItems(Value:TStrings);
begin
  FItems.Assign(Value);
end;

function TMyItemsClass.GetItems:TStrings;
begin
  Result:=FItems;
end;
0
 
BdLmCommented:

another proposal, Not sure what fit#s to your need

---------------------------------

type

  ExTStringList =class (TStringList)
  private
    FDummyFlag  :  Boolean;

    function CheckOnSet(NewValue :  Boolean) :  Boolean
  public
    property  DummyFlag : Boolean read  FDummyFlag   CheckOnSet FDummyFlag;
  end;





function  ExTStringList.CheckOnSet(NewValue :  Boolean) :  Boolean
begin
      //  your special actions

end;


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now