Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create process ..

Posted on 1999-07-05
8
Medium Priority
?
208 Views
Last Modified: 2010-04-06
I have a TList full of objects (http-components, including TMemoryStreams) that I want to free. The problem is that it takes too long time. Therefore I would like to create a new process that handles this in the background. Does anyone have some code for this.
0
Comment
Question by:sunemangs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1386181
hi sunemangs,

what does you mean with
>I would like to create a new process that handles this in the background

if you mean to start an other app,
then i don't think that this is possible

does it help, when you include
application.processmessages
in your freeing loop?

meikl
0
 

Author Comment

by:sunemangs
ID: 1386182
Well, I tied that and it didn’t help. Isn’t it possible to create a process/thread (with  CreateProcess)  that runs parallel with the rest of the code ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1386183
hi sunemangs,

it should be possible to create a thread-object,
which will do the rest.

meikl
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Expert Comment

by:Madshi
ID: 1386184
Hi guys, another process couldn't free the stuff, since it would have no access to the objects. But another thread could do the work. Look at the TThread object. But be careful! If you change the TList object in the new thread AND in the main thread, you can get problems! Then you should synchronize your actions, e.g. with CriticalSections. (TCriticalSection).

Regards, Madshi.
0
 

Author Comment

by:sunemangs
ID: 1386185
Does anyone have any code regarding the tread solution?
(I haven’t used threads before)
0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1386186
Look at the thread demo in the Delphi Demos directory

Edo
0
 
LVL 15

Accepted Solution

by:
simonet earned 200 total points
ID: 1386187
sunemangs,

Here is a simple TThread that can clear the TList for you. Using it is pretty straightforward:

- Add the unit to the uses clause of the unit from where it will be called
- Create the TClearListThread (use Create(false) for that)
- Assign the TList which you want to be deleted to the ListName proeprty of the Thread object.
- whenever you want to delete the list, call TClearListThread.Execute.

I haven't tested it, but it gave me a clean compile. There is also lots of room for improvement, but this is enough to get you started.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet

*********************

unit ListThread;

interface

uses
  Classes;

type
  TClearListThread = class(TThread)
  private
        procedure FreeListItem;
    { Private declarations }
  protected
    procedure Execute; override;
  public
        ListName : TList;
  end;

implementation

{ TClearListThread }

procedure TClearListThread.Execute;
begin
  { Place thread code here }
  while ListName.count>0 do
     Synchronize(FreeListItem);
end;


procedure TClearListThread.FreeListItem;
begin
  TObject(ListName[0]).free;
  ListName.Delete(0);
  ListName.pack;
end;

end.



0
 

Author Comment

by:sunemangs
ID: 1386188
Thank you very much

/Regards

Sune
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question