home *** CD-ROM | disk | FTP | other *** search
- uses crt,FRTE;
- { This program shows how FRTE can be used with a object methods,
- both static and virtual. In the class Note, their are two methods
- SetColor (static) and SetXY (virtual) which use FRTE to force a
- runtime error when a bad value (range) is passed to the method.
- When the error is trigger, FRTE gives control to the IDE and it
- brings the user back to the editor at the location where the
- method was evoked.
- }
-
- type
- note = object
- X,Y:word;
- Value:^string;
- Forecolor,BackColor:byte;
-
- constructor init;
- destructor done;
- procedure SetString(S:string);
- procedure SetXY(SX,SY:word); virtual;
- procedure SetColor(Fore,Back:byte);
- procedure Show;
- procedure Hide;
- end;
- var
- Anote : note;
-
- constructor note.init;
- begin
- Value := nil;
- end;
- destructor note.done;
- begin
- if Value<>nil then freemem(Value,length(Value^)+1);
- end;
- procedure note.SetString(S:string);
- begin
- if Value<>nil then note.done;
- getmem(Value,length(S)+1);
- Value^:=S;
- end;
- procedure Note.SetXY(Sx,SY:word);
- begin
- { Here is were FRTE is used to force a run time error }
- if (SX>80)or(SY>25)or((SX*SY)=0) then
- FrtError(Find_far_Caller(1),201);
- X := SX;
- Y := SY;
- end;
- procedure Note.SetColor(Fore,Back:byte);
- begin
- { Here is were FRTE is used to force a run time error }
- if Back>7 then FrtError(Find_far_Caller(1),201);
- ForeColor := Fore;
- BackColor := Back;
- end;
- procedure Note.Show;
- var
- temp:word;
- begin
- gotoxy(X,Y);
- temp := Textattr;
- TextAttr := Forecolor + (BackCOlor shl 4);
- write(Value^);
- end;
- procedure Note.Hide;
- begin
- end;
- { =========== MAIN ==============}
- begin
-
- { This code initializes the Object Error System and would normally
- be in the main code of a unit that contains the objects }
- ShowFRTEMessage := true;
- FRTE_Message := 'Note Error at #A ErrorCode #H #C';
- {------}
-
- with anote do
- begin
- init;
- { This line will cause error if the one is changed to an 81 }
- SetXY(1,2);
- { This line will cause an error if the second paramter is >7 }
- SetColor(7,12);
-
- SetString('This is a test.');
-
- show;
- end;
- end.
-
-
-
-