Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TStringList.Create in Object and its Behavior during runtime

Posted on 2001-08-23
9
Medium Priority
?
374 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 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