?
Solved

TStringList.Create in Object and its Behavior during runtime

Posted on 2001-08-23
9
Medium Priority
?
365 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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.

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, left to enroll

752 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