Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help, instances of custom components share memory?? Posted by DMX on 16 Jan 2003 at 10:30 PM
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.
Report
Re: Help, instances of custom components share memory?? Posted by biki on 16 Jan 2003 at 11:41 PM
Two components will never share their memory. Unless ofcourse some members are defined as 'static'...the components are classes after all. I'd guess you problem lies somewhere in your other code. Why not try using the procedure 'Assign' to copy results from s to resultlist ? I'm not too sure of Delphi, but I don't know what additems() exactly does.

~Bikram

Report
Re: Help, instances of custom components share memory?? Posted by DMX on 17 Jan 2003 at 2:02 AM
: Two components will never share their memory. Unless ofcourse some members are defined as 'static'...the components are classes after all. I'd guess you problem lies somewhere in your other code. Why not try using the procedure 'Assign' to copy results from s to resultlist ? I'm not too sure of Delphi, but I don't know what additems() exactly does.
:
~Bikram
:
:
OK I tried something different to try and track this down, In the main form, I have the typical menu setup, when accessing file>>search function (TfrmMain.filesearchclick) I changed it to simply "frmSearch.show" and it worked without a hitch.

However that defeats the purpose of trying to create it dynamically at runtime. I would like to be able to run multiple instances of that search form.

More testing:
The simple test was a variable sf:=TSearchform
sf:=Tfrmsearch.create(self);
sf.show;

it looks ok, but the fullpaths behind the scenes stops working. The custom mylist-component.additems function simply accepts a filename and adds the full path/to/file to fullpaths and the bare filename to the list.

Its as if the fullpaths variable isnt being created/initialized, any attempts to access it after creating that search from dynamically results in a list index error, even though the filelist portion is being filled with results.

Totally confusing?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.