Re: Just a simple question on .Free

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 12/01/04


Date: Wed, 1 Dec 2004 12:50:52 -0500


"Christakis John" <dontemail@me.please.ok> wrote in message
news:z7crd.54365$K7.19510@news-server.bigpond.net.au...

> One last thing - is there any way to get to the with'd object. eg:
>
> say I have this function
>
> function mycount(stl : TStringList) : integer;
> begin
> Result:=stl.Count;
> end;
>
> and then I use a stringlist in a with like this:
>
> With TStringList.Create do

I presume you forgot a Begin here.

> Strings.Add('hello');
> Strings.Add('world');
> ----
> Free;
> end;
>
> is there a way I can insert myCount() at ---- and have it use the
stringlist
> that is active there? Does that make sense? I tried 'Self' but that
didn't
> work.

With is not a good construct to use in Delphi. A google search of this ng
will turn up multiple threads as to why. I'd suggest a coding more like

var myStringList : tStringList;

. . .
myStringList : tStringList.Create;
try
    myStringList.Add ('hello');
    myStringList.Add ('world');
    . . .
    ShowMessage ('Count is ' + IntToStr (myCount (myStringList)));
    . . .
finally
    myStringList.Free;
    end;
. . .



Relevant Pages

  • Re: Search Tool for FP Website
    ... we select we get the same result, a google search page is opened and we ... Any ideas where we're going wrong or would it help if i posted the coding ... Ron Symonds - Microsoft MVP (FrontPage) ... The webpage is basically one huge table and the code is going within ...
    (microsoft.public.frontpage.programming)
  • Re: [QC48712] Help system: No top entries in Reference for RTL routines(Categorical Routines Listing
    ... Other programmers not using delphi will come across delphi if they mistakenly land upon some nice online docs while looking for visual basic functions that have the same name. ... but the internet and google are free advertising for delphi - and people ARE addicted to the google search box no matter how much we want to deny it. ...
    (borland.public.delphi.non-technical)
  • Re: Turbo Delphi Purchase Questions
    ... my code in Delphi which works well for QR, ... Pascal script suggests that you have to do that rather than coding it ... Our software contains reports which are compiled in, ...
    (borland.public.delphi.non-technical)
  • Re: I have seen some fat client Dot Net apps
    ... RAD, like in Delphi, is also just an advantage for the software ... developer. ... And yet coding for a GUI would take much longer and be more ...
    (borland.public.delphi.non-technical)
  • Re: Component Rankings, Startup Advice and other random tidbits
    ... To those of you that started an ISV: ... Did you do all the coding yourself on your first project? ... considering starting a new commercial software startup... ... I like the speed of app development in Delphi. ...
    (borland.public.delphi.non-technical)