I am working on a media player, just a little something that has the features I need.
I built upon TListBox component and simply added a Tstringlist to store the full "drive:/path/to/file", while the shows just shows the "filename.extension"
I compiled and installed the unit under [standard] with no problem, and dropped it unto my main form and all was well.
here is the type declaration for it
type
TMyListBox3 = class(TListBox)
Constructor Create(AOwner : TComponent); override;
Destructor Destroy; override;
private
{ Private declarations }
SaveDialog : TSaveDialog;
protected
{ Protected declarations }
public
{ Public declarations }
fullpaths : TStringList;
function GetFullName(I : LongInt) : String;
function Count : LongInt;
procedure AddItems(s : TStringList);
procedure DeleteSelectedItems();
published
{ Published declarations }
end;
Nothing too complicated right?
However, I created a new form (FrmSearch) and dropped that custom component on it and setup a few functions.
The FrmSearch's search function, searches the main form's list for a specified keyword and when It finds a match it addes the main fullpath to its own fullpath so you can just click right on a search result and play directly from there, (the play function takes a string argument).
Here is the problem, after a search, the frmSearch's getfullname returns information from the MAIN playlist, obviously thats incorrect.
For example, if you search for xyz and it is found at the 5th index on the main form, it is placed on the 1st (or whatever) index on the search form, however accessing it is like accessing the main form.
The expected behavior is frmSearch.SearchResults.items[0]="xyz", but instead frmsearch.SearchResults.items[0] ALWAYS equalts frmMain.MyList1.items[0], index for index they always match.
The code shows that isnt possible, but it is:
procedure TFrmSearch.SearchList(SearchString: String);
var
i,l : Integer;
s : Tstringlist;
begin
s := Tstringlist.Create;
l:=frmmain.MyList1.Count-1;
for i:=0 to l do
begin
if pos(Lowercase(SearchString),Lowercase(frmmain.MyList1.GetFullName(i) ))<>0 then
begin
s.add(frmmain.MyList1.GetFullName(i));
end;
end;
self.resultlist.additems(s);
s.free;
end;
It seems as though the two seperate instances of the custom (mylist) component are sharing memory.
Any ideas? sorry for the long post, but I didnt want there to be any doubt about the code.