+ Added exceptions for error handling

This commit is contained in:
michael 1998-10-02 22:41:23 +00:00
parent 906cf3d453
commit 1b126ff278
7 changed files with 86 additions and 66 deletions

View File

@ -198,8 +198,7 @@ function TCollection.GetItemAttr(Index, ItemIndex: Integer): string;
begin
//!! Not Accepted !!
//!! Result:=TCollectionItem(FItems[ItemIndex]).DisplayName;
Result:=TCollectionItem(FItems[ItemIndex]).DisplayName;
end;
@ -231,7 +230,7 @@ end;
function TCollection.GetItem(Index: Integer): TCollectionItem;
begin
//!! Result:=FItems[Index];
Result:=TCollectionItem(FItems[Index]);
end;
@ -239,7 +238,7 @@ end;
procedure TCollection.SetItem(Index: Integer; Value: TCollectionItem);
begin
//!! TCollectionItem(FItems[Index]).Assign(Value);
TCollectionItem(FItems[Index]).Assign(Value);
end;
@ -313,8 +312,8 @@ end;
procedure TCollection.Clear;
begin
//!! If Assigned(FItems) then
//!! While FItems.Count>0 do TCollectionItem(FItems.Last).Free;
If Assigned(FItems) then
While FItems.Count>0 do TCollectionItem(FItems.Last).Free;
end;
@ -334,14 +333,17 @@ begin
Result:=Nil;
For I:=0 to Fitems.Count-1 do
begin
//!! Result:=TCollectionItem(FItems[I]);
Result:=TCollectionItem(FItems[I]);
If Result.Id=Id then exit;
end;
end;
{
$Log$
Revision 1.2 1998-05-27 11:41:41 michael
Revision 1.3 1998-10-02 22:41:23 michael
+ Added exceptions for error handling
Revision 1.2 1998/05/27 11:41:41 michael
Implemented TCollection and TCollectionItem
Revision 1.1 1998/05/04 14:30:11 michael

View File

@ -147,11 +147,12 @@ begin
Temp:=0;
Ancestor:=TComponent(Filer.Ancestor);
If Assigned(Ancestor) then Temp:=Ancestor.FDesignInfo;
{
Filer.Defineproperty('left',readleft,writeleft,
(longrec(FDesignInfo).Lo<>Longrec(temp).Lo));
Filer.Defineproperty('top',readtop,writetop,
(longrec(FDesignInfo).Hi<>Longrec(temp).Hi));
}
end;
@ -260,8 +261,7 @@ Procedure TComponent.SetName(const NewName: TComponentName);
begin
If FName=NewName then exit;
If not IsValidIdent(NewName) then
//!!
runerror(255);
Raise EComponentError.CreateFmt(SInvalidName,[NewName]);
If Assigned(FOwner) Then
FOwner.ValidateRename(Self,FName,NewName)
else
@ -314,8 +314,7 @@ begin
//!! This contradicts the Delphi manual.
If (AComponent<>Nil) and (CurName=NewName) and
(FindComponent(NewName)<>Nil) then
//!! raise EComponentError.Createfmt(SDuplicatename[newname])
runerror(255);
raise EComponentError.Createfmt(SDuplicateName,[newname]);
If (csDesigning in FComponentState) and (FOwner<>Nil) then
FOwner.ValidateRename(AComponent,Curname,Newname);
end;
@ -478,7 +477,10 @@ end;
{
$Log$
Revision 1.4 1998-08-24 12:37:44 michael
Revision 1.5 1998-10-02 22:41:25 michael
+ Added exceptions for error handling
Revision 1.4 1998/08/24 12:37:44 michael
small fixes
Revision 1.3 1998/08/23 21:11:03 michael

View File

@ -34,10 +34,9 @@ const
SDuplicateString = 'Duplicate entries not allowed in StringList';
SInvalidTabIndex = 'Registerindex out of bounds';
SDuplicateName = 'A Component with name %s exists already';
SInvalidName = '''''%s'''' is not a valid identifier name';
SInvalidName = '"%s" is not a valid identifier name';
SDuplicateClass = 'A Class with name %s exists already';
SNoComSupport = '%s is not registered as COM-Class';
SInvalidInteger = '''''%s'''' is not a valid integer value';
SLineTooLong = 'Line too long';
SInvalidPropertyValue = 'Invalid property value';

View File

@ -30,7 +30,7 @@ function TList.Get(Index: Integer): Pointer;
begin
If (Index<0) or (Index>FCount) then
Runerror (255);
Error(SListIndexError,Index);
Result:=FList^[Index];
end;
@ -48,7 +48,7 @@ procedure TList.Put(Index: Integer; Item: Pointer);
begin
if (Index<0) or (Index>=FCount) then
Runerror(255);
Error(SListIndexError,Index);
Flist^[Index]:=Item;
end;
@ -60,12 +60,13 @@ Var NewList,ToFree : PPointerList;
begin
If (NewCapacity<0) or (NewCapacity>MaxListSize) then
RunError (255);
Error (SListCapacityError,NewCapacity);
If NewCapacity>FCapacity then
begin
GetMem (NewList,NewCapacity*SizeOf(Pointer));
If NewList=Nil then
Runerror(255);
//!! Find another one here !!
Error (SListCapacityError,NewCapacity);
If Assigned(FList) then
begin
System.Move (FList^,NewList^,FCapacity*Sizeof(Pointer));
@ -78,7 +79,7 @@ begin
else if NewCapacity<FCapacity then
begin
If NewCapacity<0 then
RunError(255);
Error (SListCapacityError,NEwCapacity);
ToFree:=Flist+NewCapacity*SizeOf(Pointer);
FreeMem (ToFree, (FCapacity-NewCapacity)*SizeOf(Pointer));
FCapacity:=NewCapacity;
@ -91,7 +92,7 @@ procedure TList.SetCount(NewCount: Integer);
begin
If (NewCount<0) or (NewCount>MaxListSize)then
RunError(255);
Error(SListCountError,NewCount);
If NewCount<FCount then
FCount:=NewCount
else If NewCount>FCount then
@ -141,7 +142,7 @@ Procedure TList.Delete(Index: Integer);
begin
If (Index<0) or (Index>=FCount) then
Runerror(255);
Error (SListIndexError,Index);
FCount:=FCount-1;
System.Move (FList^[Index+1],FList^[Index],(FCount-Index)*SizeOf(Pointer));
end;
@ -150,8 +151,8 @@ end;
class procedure TList.Error(const Msg: string; Data: Integer);
begin
Writeln (Msg);
RunError(255);
//!! Find a way to get call address
Raise EListError.CreateFmt(Msg,[Data]);
end;
procedure TList.Exchange(Index1, Index2: Integer);
@ -159,9 +160,10 @@ procedure TList.Exchange(Index1, Index2: Integer);
var Temp : Pointer;
begin
If ((Index1>=FCount) or (Index2>=FCount)) or
((Index1<0) or (Index2<0)) then
RunError(255);
If ((Index1>=FCount) or (Index1<0)) then
Error(SListIndexError,Index1);
If ((Index2>=FCount) or (Index2<0)) then
Error(SListIndexError,Index2);
Temp:=FList^[Index1];
FList^[Index1]:=FList^[Index2];
FList^[Index2]:=Temp;
@ -206,7 +208,7 @@ procedure TList.Insert(Index: Integer; Item: Pointer);
begin
If (Index<0) or (Index>FCount )then
RunError(255);
Error(SlistIndexError,Index);
IF FCount=FCapacity Then Self.Expand;
If Index<FCount then
System.Move (Flist^[Index],Flist^[Index+1],(FCount-Index)*SizeOf(Pointer));
@ -231,8 +233,10 @@ procedure TList.Move(CurIndex, NewIndex: Integer);
Var Temp : Pointer;
begin
If ((CurIndex<0) or (CurIndex>Count-1)) or (NewINdex<0) then
RunError(255);
If ((CurIndex<0) or (CurIndex>Count-1)) then
Error(SListIndexError,CurIndex);
If (NewINdex<0) then
Error(SlistIndexError,NewIndex);
Temp:=FList^[CurIndex];
Self.Delete(CurIndex);
// ?? If NewIndex>CurIndex then NewIndex:=NewIndex-1;
@ -386,7 +390,10 @@ end;
{
$Log$
Revision 1.4 1998-05-06 07:27:22 michael
Revision 1.5 1998-10-02 22:41:27 michael
+ Added exceptions for error handling
Revision 1.4 1998/05/06 07:27:22 michael
+ Fixec index check in exchange method.
Revision 1.3 1998/05/05 15:54:31 michael

View File

@ -101,7 +101,7 @@ end;
destructor TParser.Destroy;
begin
if FBuffer <> nil then
if Assigned(FBuffer) then
begin
FStream.Seek(Longint(FTokenPtr) - Longint(FBufPtr), 1);
FreeMem(FBuffer, ParseBufSize);
@ -322,7 +322,10 @@ begin
end;
{
$Log$
Revision 1.2 1998-09-23 07:48:11 michael
Revision 1.3 1998-10-02 22:41:28 michael
+ Added exceptions for error handling
Revision 1.2 1998/09/23 07:48:11 michael
+ Implemented by TSE
Revision 1.1 1998/05/04 14:30:12 michael

View File

@ -26,8 +26,7 @@ begin
else
SourceName:='Nil';
Writeln ('Error assigning to ',ClassName,' from : ',SourceName);
RunError(255);
//!! raise EConvertError.CreateFmt (SAssignError,[SourceName,ClassName]);
raise EConvertError.CreateFmt (SAssignError,[SourceName,ClassName]);
end;
@ -82,7 +81,10 @@ begin
end;
{
$Log$
Revision 1.2 1998-05-27 12:22:14 michael
Revision 1.3 1998-10-02 22:41:29 michael
+ Added exceptions for error handling
Revision 1.2 1998/05/27 12:22:14 michael
+ Implemented TPersistent
Revision 1.1 1998/05/04 14:30:12 michael

View File

@ -49,22 +49,14 @@
begin
if Read(Buffer,Count)<Count then
{$ifdef NoExceptions}
;
{$else}
Raise(EReadError);
{$endif}
Raise EReadError.Create(SReadError);
end;
procedure TStream.WriteBuffer(const Buffer; Count: Longint);
begin
if Write(Buffer,Count)<Count then
{$ifdef NoExceptions}
;
{$else}
Raise(EWriteError);
{$endif}
Raise EWriteError.Create(SWriteError);
end;
function TStream.CopyFrom(Source: TStream; Count: Longint): Longint;
@ -118,9 +110,12 @@
Writer : TWriter;
begin
Writer.Create(Self,1024);
Writer.WriteRootComponent(Instance);
Writer.Destroy;
Try
Writer.Create(Self,1024);
Writer.WriteRootComponent(Instance);
Finally
Writer.Destroy;
end;
end;
procedure TStream.WriteComponentRes(const ResName: string; Instance: TComponent);
@ -170,15 +165,15 @@
try
{ application specific resource ? }
if ReadByte<>$ff then
raise EInvalidImage.Create;
raise EInvalidImage.Create('');
if ReadWord<>$000a then
raise EInvalidImage.Create;
raise EInvalidImage.Create('');
{ read name }
while ReadByte<>0 do
;
{ check the access specifier }
if ReadWord<>$1030 then
raise EInvalidImage.Create;
raise EInvalidImage.Create('');
{ ignore the size }
ReadDWord;
except
@ -186,7 +181,7 @@
on EInvalidImage do
raise;
else
raise(EInvalidImage);
raise EInvalidImage.create(SInvalidImage);
}
end;
{$endif Win16Res}
@ -306,11 +301,10 @@ constructor TFileStream.Create(const FileName: string; Mode: Word);
begin
FHandle:=OSCreateFile (Filename,Mode);
If FHandle<0 then
{$ifdef NoExceptions}
RunError(255);
{$else}
raise EFCreateError;
{$endif}
If Mode=fmcreate then
raise EFCreateError.createfmt(SFCreateError,[FileName])
else
raise EFOpenError.Createfmt(SFOpenError,[Filename]);
end;
@ -384,9 +378,12 @@ procedure TCustomMemoryStream.SaveToFile(const FileName: string);
Var S : TFileStream;
begin
S:=TFileStream.Create (FileName,fmCreate);
SaveToStream(S);
S.free;
Try
S:=TFileStream.Create (FileName,fmCreate);
SaveToStream(S);
finally
S.free;
end;
end;
@ -419,6 +416,8 @@ begin
else
begin
GetMem (Result,NewCapacity);
If Result=Nil then
Raise EStreamError.Create(SMemoryStreamError);
If FCapacity>0 then
begin
MoveSize:=FSize;
@ -461,9 +460,12 @@ procedure TMemoryStream.LoadFromFile(const FileName: string);
Var S : TFileStream;
begin
S:=TFileStream.Create (FileName,fmOpenRead);
LoadFromStream(S);
S.free;
Try
S:=TFileStream.Create (FileName,fmOpenRead);
LoadFromStream(S);
finally
S.free;
end;
end;
@ -608,7 +610,10 @@ end;
{
$Log$
Revision 1.7 1998-08-24 12:38:24 michael
Revision 1.8 1998-10-02 22:41:30 michael
+ Added exceptions for error handling
Revision 1.7 1998/08/24 12:38:24 michael
small fixes
Revision 1.6 1998/06/11 21:15:28 michael