Solved

TStringList.Create in Object and its Behavior during runtime

Posted on 2001-08-23
9
335 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 206
Newbie Thread Programming 1 139
Base1 Encode/Decode 3 68
Dev express lookupcombo 3 14
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 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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

23 Experts available now in Live!

Get 1:1 Help Now