Board index » delphi » Problems using Delphi 2.0

Problems using Delphi 2.0

I am trying to compile a source in 2.0 which works in Delphi 1.0 but there
are two things that I can not solve/explain :

1)
function  TLinkage.GetTBLField(ALevel, index: integer): TTable;
begin
  result := nil;
  try
    with (FDBLinkList.Objects[FIndex] as TDBLink) do
    with  FViewList.Objects[Alevel] as TLevel do begin
      case index of
        1:  result := FTable;
        2:  result := FViewTable;
      end;
    end;
  except result := nil;
  end;
end;

Now when Alevel is out of range in my opinion it should generate a
exception and jump to my "except" line (as it does in 1.0). But it just
generates a error message.
Why doesn't this work as it should ????????

2)
I seems that an IF expression checks after AND even if the expression
result was False :

      if (ViewTable[NLev] <> nil) and (not
TblList.Find(ViewTable[NLev].Name, Nr)) then begin

Now if the first part is not true it should stop (just as 1.0 does) but is
doesn't. In this case the second check results in an error message. Of
course you can overcome this problem by splitting the statement in two
parts :

      if (ViewTable[NLev] <> nil) then
        if (not TblList.Find(ViewTable[NLev].Name, Nr)) then begin

Why is the second part evaluated ????????

I just downloaded the new system.dcu and installed it (don't know what has
been solved) could this cause any problems ?

Thanks for your help!

 

Re:Problems using Delphi 2.0


D. van der Zee <sy...@euronet.nl> wrote in article
<01bb971f$c1e96760$910886c2@dirk>...

    ...

Quote
>   try
>   except result := nil;
>   end;
> Now when Alevel is out of range in my opinion it should generate a
> exception and jump to my "except" line (as it does in 1.0). But it just
> generates a error message.
> Why doesn't this work as it should ????????

Have you noticed that you are not acutally trapping the error?

Within your EXCEPT block, you need to say something like:
    ON _SOME_EXCEPTION_TYPE_ DO
        result := nil;

This destroys the Exception instance and keeps the exception from
propagating outsideyour handler.

Quote
> 2)
> I seems that an IF expression checks after AND even if the expression
> result was False :

>       if (ViewTable[NLev] <> nil) and (not
> TblList.Find(ViewTable[NLev].Name, Nr)) then begin

> Now if the first part is not true it should stop (just as 1.0 does) but
is
> doesn't. In this case the second check results in an error message.

Have you checked your Project Options to make sure that Complete Boolean
Evaluation is turned off?

Hope this helped.

Re:Problems using Delphi 2.0


Quote
> >   try
> >   except result := nil;
> >   end;
> Have you noticed that you are not acutally trapping the error?
> This destroys the Exception instance and keeps the exception from
> propagating outsideyour handler.

Not quite correct.  The code above traps all exceptions, regardless of their type.  The instance
is still destroyed, as in this code -

   try
       raise EConvertError.Create('Test');
   except
       ShowMessage('Conversion exception');
   end;
   ShowMessage('This code executes');

Quote
> > 2)
> > I seems that an IF expression checks after AND even if the expression
> > result was False :

> >       if (ViewTable[NLev] <> nil) and (not
> > TblList.Find(ViewTable[NLev].Name, Nr)) then begin

> > Now if the first part is not true it should stop (just as 1.0 does) but
> is
> > doesn't. In this case the second check results in an error message.
> Have you checked your Project Options to make sure that Complete Boolean
> Evaluation is turned off?

I agree with this.

--
Mark.

Re:Problems using Delphi 2.0


D. van der Zee wrote:

Quote

> I am trying to compile a source in 2.0 which works in Delphi 1.0 but there
> are two things that I can not solve/explain :

> 1)
> function  TLinkage.GetTBLField(ALevel, index: integer): TTable;
> begin
>   result := nil;
>   try
>     with (FDBLinkList.Objects[FIndex] as TDBLink) do
>     with  FViewList.Objects[Alevel] as TLevel do begin
>       case index of
>         1:  result := FTable;
>         2:  result := FViewTable;
>       end;
>     end;
>   except result := nil;
>   end;
> end;

> Now when Alevel is out of range in my opinion it should generate a
> exception and jump to my "except" line (as it does in 1.0). But it just
> generates a error message.
> Why doesn't this work as it should ????????

> 2)
> I seems that an IF expression checks after AND even if the expression
> result was False :

>       if (ViewTable[NLev] <> nil) and (not
> TblList.Find(ViewTable[NLev].Name, Nr)) then begin

> Now if the first part is not true it should stop (just as 1.0 does) but is
> doesn't. In this case the second check results in an error message. Of
> course you can overcome this problem by splitting the statement in two
> parts :

>       if (ViewTable[NLev] <> nil) then
>         if (not TblList.Find(ViewTable[NLev].Name, Nr)) then begin

> Why is the second part evaluated ????????

> I just downloaded the new system.dcu and installed it (don't know what has
> been solved) could this cause any problems ?

> Thanks for your help!

Check your complier options.  You may want range checking truned on for
the first problem and Complete Boolean Evaluation turned off for the
secound problem.

Mike

Other Threads