troubleshooting Question

Expand the Listbox ADD function

Avatar of LMuadDIb
LMuadDIbFlag for United States of America asked on
Delphi
2 Comments1 Solution331 ViewsLast Modified:
Hello All.
What Im trying to do is create a Listbox component (derived from TCustomListBox) D7
This Listbox will have three columns, first col has an image, the second col has a timestamp and the third col will display text msg. Its gonna be used for logging.

In the TListBoxItemCollection you have the standard function --

  function Add:TListBoxLogItem;

I want to add a couple new function(s) that basically do the same --

    function AddStatus:TListBoxLogItem;
    function AddWarning:TListBoxLogItem;
    function AddError:TListBoxLogItem;

and/or

    function AddStatus(const Value: string):TListBoxLogItem;
    function AddWarning(const Value: string):TListBoxLogItem;
    function AddError(const Value: string):TListBoxLogItem;

with the above function I want to add default values. Like default ImageIndex, default Timestamp etc...
that way I do not have to manually code the defs like so:

procedure TForm1.Button1Click(Sender: TObject);
var
  formatSettings : TFormatSettings;
begin

 GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, formatSettings); //-- Thread Safe

 with ListboxLog1.ListBoxItems.Add do
  begin
   ImageIndex:=random(3);
   Strings.Add(DateTimeToStr(now, formatSettings));
   Strings.Add('Item '+inttostr(ENuDListboxLog1.Items.Count-1));
  end;
end;

I want to be able to do this:

procedure TForm1.Button1Click(Sender: TObject);
begin
 ENuDListboxLog1.ListBoxItems.AddStatus('Some status text to display') ;
end;

I have added those extra functions and tried to adjust the result before and after the ADD, but I either get errors or the results return '' text in the item:

function TListBoxLogItemCollection.AddStatus(const Value: string): TListBoxLogItem;
var
  formatSettings : TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, formatSettings); //-- Thread Safe
  Result.FImageIndex := 1;
  Result.fStrings.Clear;
  Result.fStrings.Add(DateTimeToStr(now, formatSettings));
  Result.fStrings.Add(Value);

  Result:=TListBoxLogItem(inherited Add);

end;

Any help wuold be appreciated. thank you
Paul
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros