Brian
2010-02-08 18:59:31 UTC
I have a program that creates an object, destroys it, and then tries
to access it. The intent here is to cause and exception and then to
catch it. Thing is, I can't seem to catch it. Here is my program.
Any ideas why I can't seem to catch it?
brian
program Greeting;
{$APPTYPE CONSOLE}
uses
Unit1,
sysutils;
type
PCar = ^TCar;
var
myCar:TCar;
myPCar: PCar;
begin
bar := 20;
myCar.Create;
myPCar := @myCar;
myCar.Destroy;
try
Writeln('the car is running ', myCar.getRunning );
except
on Exception do Beep;
end;
end.
Here is Unit1.pas in case you want to see the code to it as well.
nit Unit1;
interface
type TCar = class
private
Frunning: boolean;
public
procedure Start;
procedure Stop;
function getRunning: boolean;
end;
implementation
procedure TCar.Start;
begin
Frunning := true;
end;
procedure TCar.Stop;
begin
Frunning := false;
end;
function TCar.getRunning: boolean;
begin
result := Frunning;
end;
end.
to access it. The intent here is to cause and exception and then to
catch it. Thing is, I can't seem to catch it. Here is my program.
Any ideas why I can't seem to catch it?
brian
program Greeting;
{$APPTYPE CONSOLE}
uses
Unit1,
sysutils;
type
PCar = ^TCar;
var
myCar:TCar;
myPCar: PCar;
begin
bar := 20;
myCar.Create;
myPCar := @myCar;
myCar.Destroy;
try
Writeln('the car is running ', myCar.getRunning );
except
on Exception do Beep;
end;
end.
Here is Unit1.pas in case you want to see the code to it as well.
nit Unit1;
interface
type TCar = class
private
Frunning: boolean;
public
procedure Start;
procedure Stop;
function getRunning: boolean;
end;
implementation
procedure TCar.Start;
begin
Frunning := true;
end;
procedure TCar.Stop;
begin
Frunning := false;
end;
function TCar.getRunning: boolean;
begin
result := Frunning;
end;
end.