List Info

Thread: Re: Try Except Usage




Re: Try Except Usage
user name
2007-01-22 03:25:19

You have declared the function as returning a string, and then try to return a blank(!).
Try using
Result := '';
instead of
Result := Blank;

Paul

> ----- Original Message -----
&gt; From: edsynergy < ed%40synergynewmedia.co.uk">edsynergynewmedia.co.uk>
&gt; To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
&gt; Subject: [delphi-en] Try Except Usage
&gt; Date: Sat, 20 Jan 2007 16:08:25 -0000
&gt;
>
> Here is a small function that extracts a string from a resource dll.
>; Works fine when the resource is there, and I get an EResNotFound When
>; one is not found. However when the code in the exception clause is run
> (on EResNotFound do Result:= blank;) it immetiately gives an AV. In
> fact it dos'nt matter what code I put in the exception I get the AV
> I cant see what the problem is
>
> Best wishe Ed.
>
> function TformMainTasks.SetAnchorText(const ResString:string):string;
>; var
> ls:Tstringlist;
>; ms:TresourceStream;
> h:Thandle;
> begin
&gt;
> try
> h := LoadLibrary(pchar('strings.dll'));
> try
> ms:=TresourceStream.Create(h,ResString, RT_RCDATA);
> if ( Assigned(ms)) then
>; begin
&gt; try
> ls:= TstringList.Create;
> ms.Position:= 0;
> ls.LoadFromStream(ms);
> Result:= ls.Text;
> finally
> ls.Free;
> // free resources
> end; // try/finally
> End
> Else Result:= blank;
&gt; except
&gt; on EResNotFound do Result:= blank;
&gt; end; // try/except
> finally
> ms.Free;
> FreeLibrary(h);
&gt;
> // free resources
> end; // try/finally
> end;

>

Experience is something you don't get until just after you need it.

--
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 9 at http://www.opera.com

Powered by Outblaze

__._,_.___
.

__,_._,___
Re: Try Except Usage
user name
2007-01-22 04:39:01

Paul,
Sorry my code as imcomplete. Blank is a constant set to ''

However the problem was solved by a code change suggested by Rob

Best wished Ed

--- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, "Paul Bennett&quot; <rm28157...> wrote:
&gt;
> You have declared the function as returning a string, and then try
to return a blank(!).
> Try using
> Result := '';
> instead of
> Result := Blank;
&gt;
> Paul
>;
> > ----- Original Message -----
&gt; > From: edsynergy <ed...>
> > To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
&gt; > Subject: [delphi-en] Try Except Usage
&gt; > Date: Sat, 20 Jan 2007 16:08:25 -0000
&gt; >
> >
> > Here is a small function that extracts a string from a resource dll.
>; > Works fine when the resource is there, and I get an EResNotFound When
>; > one is not found. However when the code in the exception clause is run
> > (on EResNotFound do Result:= blank;) it immetiately gives an AV. In
> > fact it dos'nt matter what code I put in the exception I get the AV
> > I cant see what the problem is
> >
> > Best wishe Ed.
> >
> > function TformMainTasks.SetAnchorText(const ResString:string):string;
>; > var
> > ls:Tstringlist;
>; > ms:TresourceStream;
> > h:Thandle;
> > begin
&gt; >
> > try
> > h := LoadLibrary(pchar('strings.dll'));
> > try
> > ms:=TresourceStream.Create(h,ResString, RT_RCDATA);
> > if ( Assigned(ms)) then
>; > begin
&gt; > try
> > ls:= TstringList.Create;
> > ms.Position:= 0;
> > ls.LoadFromStream(ms);
> > Result:= ls.Text;
> > finally
> > ls.Free;
> > // free resources
> > end; // try/finally
> > End
> > Else Result:= blank;
&gt; > except
&gt; > on EResNotFound do Result:= blank;
&gt; > end; // try/except
> > finally
> > ms.Free;
> > FreeLibrary(h);
&gt; >
> > // free resources
> > end; // try/finally
> > end;
>;
> >
>;
>
>
> Experience is something you don't get until just after you need it.
>
>
> --
> _______________________________________________
> Surf the Web in a faster, safer and easier way:
>; Download Opera 9 at http://www.opera.com
>
> Powered by Outblaze
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )