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 -----
> From: edsynergy < ed%40synergynewmedia.co.uk">edsynergynewmedia.co.uk>
> To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
> Subject: [delphi-en] Try Except Usage
> Date: Sat, 20 Jan 2007 16:08:25 -0000
>
>
> 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
>
> try
> h := LoadLibrary(pchar('strings.dll'));
> try
> ms:=TresourceStream.Create(h,ResString, RT_RCDATA);
> if ( Assigned(ms)) then
> begin
> 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;
> except
> on EResNotFound do Result:= blank;
> end; // try/except
> finally > ms.Free;
> FreeLibrary(h);
>
> // 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
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" <rm28157...> wrote:
>
> 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 -----
> > From: edsynergy <ed...> > > To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
> > Subject: [delphi-en] Try Except Usage
> > Date: Sat, 20 Jan 2007 16:08:25 -0000
> >
> >
> > 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
> >
> > try
> > h := LoadLibrary(pchar('strings.dll'));
> > try
> > ms:=TresourceStream.Create(h,ResString, RT_RCDATA);
> > if ( Assigned(ms)) then
> > begin
> > 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;
> > except
> > on EResNotFound do Result:= blank;
> > end; // try/except
> > finally > > ms.Free;
> > FreeLibrary(h);
> >
> > // 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
>