Solved

TStringList.Create in Object and its Behavior during runtime

Posted on 2001-08-23
9
330 Views
Last Modified: 2010-07-27
I create a class A of Tform as an object, and it has a
array of TStringList. I create them at the A.Create().
This lists will load values files in procedure
A.Getlist ().  In the begining, the 1st call of GetList
is alright, and when I add watcher to  List[0].text

procedure GetList ();
begin
    List[0].clear;
    List[0].add(FloatToStr(OtherSource));
    :
0
Comment
Question by:aavictor
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Author Comment

by:aavictor
ID: 6418255
After the cursor left GetList, List[0].text becomes
inaccessible in this object.
When recall this method, List[0].clear will cause
access violation.

But List[1] is still accessible and debugger can recall
the value from text. That makes me puzzle why List[0]
will be after it quits method GetList.

and How to fix it?
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6419823
Did you declare List in the declarations of the Class?

John.
0
 
LVL 4

Author Comment

by:aavictor
ID: 6419928
yes.

Temporarily, I force to create TStringList each time of\
using this method. However, it is  strange that the memory
becomes inaccessible in this class when the method is
end. The memory consumption grows each time of the call.

List      : array[0..2] of TStringList;
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6419933
I'm afraid I'll have to see a little more of the code.  Could you show me the declarations in your custom class and also the create command from the parent form.

John.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 6421353
yup, show a bit more code,
specially the sections where you create and destroy the lists, also you getlist procedure would be from interest

(guessing you never create the tstringslists, or
you are loosing the lists-reference somewhere)

meikl ;-)
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6421356
Agreed.
0
 
LVL 4

Author Comment

by:aavictor
ID: 6424431
procedure Aclass.GetRateNews ;
begin
    TIntRatePlugIn.create;
    if (RateNews.PlugIn.Int_error <> 0) then
    begin
           rateEdit.clear;
    end
    else
    begin
           rateEdit.Text := Format('%.2n', [RateNews.Rate * 100.0]);
           opt.DiscountRate.ItemQty := 1;
           opt.DiscountRate.ItemSet.list[0].term := RateNews.timeRemain;
           opt.DiscountRate.ItemSet.list[0].rate := RateNews.Rate;
           opt.LoanRate.ItemQty := 1;
           opt.LoanRate.ItemSet.list[0].term := RateNews.timeRemain;
           opt.LoanRate.ItemSet.list[0].rate := RateNews.Rate;
// currently I do to resolve the access violation
           if (DisRateList[0] = nil) then DisRateList[0] := TStringList.Create;
           if (DisRateList[1] = nil) then DisRateList[1] := TStringList.Create;
//=========================
// The pointer is here. If I take out the create code,
// error comes, and memory is freed by somewhere which
// I can't find any hint or trace
//=========================
           DisRateList[0].Clear;
           DisRateList[0].Add(FloatToStr(RateNews.timeRemain));
           DisRateList[1].Clear;
           DisRateList[1].Add(FloatToStr(RateNews.rate));
           if (LoanList[0] = nil) then
           begin
                LoanList[0] := TStringList.Create;
                LoanList[0].Add(FloatToStr(RateNews.timeRemain));
                writeln (LoanList[0].text);
           end
           else
           begin
                        if (LoanList[0]<>nil) then LoanList[0].free;
                        LoanList[0] := TStringList.Create;
                        LoanList[0].Add(FloatToStr(RateNews.timeRemain));
           end;
           if (LoanList[1] = nil) then
           begin
                LoanList[1] := TStringList.Create;
                LoanList[1].Add(FloatToStr(RateNews.rate));
           end
           else
           begin
                try
                        if (LoanList[1].Count < 0) then LoanList[1] := TStringList.Create;
                except
                        LoanList[1] := TStringList.Create;
                end;

                if (LoanList[1].Count < 1) then
                begin
                        LoanList[1].Add(FloatToStr(RateNews.rate));
                end
                else
                begin
                        LoanList[1].clear;
                        LoanList[1].Add(FloatToStr(RateNews.rate));
                end;
           end;

    end;

end;
//============== That's all I can show due to commerical
// reason. However, my assumption is that TStringList
//object is here, why count is inaccessible when I use
// debugger. Do you give me some hint about Delphi's
// memory-management behavior, and how to resolve it
// rather than a new problem I created --- it eats
// my PC memory 100 K byte per call of this method
0
 
LVL 4

Author Comment

by:aavictor
ID: 6424552
because of your remind
"you are loosing the lists-reference somewhere"

I walk thru the code line by line from each unit
and I find that there is no free statement before
some create statements. Thank

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6424558
hum, thanks :-)
(never guessed a grading)

hope you get it work without leaks
good luck again

meikl ;-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now