Solved

TStringList.Create in Object and its Behavior during runtime

Posted on 2001-08-23
9
353 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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