Wrapped ComponentToString with a Try-Except so when you delete a control it doesn't crash.

Shane

git-svn-id: trunk@377 -
This commit is contained in:
lazarus 2001-10-31 19:48:21 +00:00
parent 07f6e25d94
commit 0b9d70ec39
5 changed files with 63 additions and 20 deletions

View File

@ -25,9 +25,12 @@ unit ControlSelection;
interface interface
uses uses
Classes, LCLLinux, Controls, Forms, Graphics; Classes, LCLLinux, Controls, Forms, Graphics,SysUtils;
type type
GenException = class(Exception);
TGrabberMoveEvent = procedure(Sender: TObject; dx, dy: Integer) of object; TGrabberMoveEvent = procedure(Sender: TObject; dx, dy: Integer) of object;
TGrabIndex = 0..7; TGrabIndex = 0..7;
@ -223,7 +226,7 @@ implementation
uses uses
Sysutils, Math; Math;
const const
GRAB_CURSOR: array[TGrabIndex] of TCursor = ( GRAB_CURSOR: array[TGrabIndex] of TCursor = (
@ -436,11 +439,17 @@ end;
procedure TControlSelection.EndUpdate; procedure TControlSelection.EndUpdate;
begin begin
if FUpdateLock<=0 then exit; if FUpdateLock<=0 then exit;
dec(FUpdateLock); Writeln('1');
if FUpdateLock=0 then begin dec(FUpdateLock);
if FChangedDuringLock then DoChange; if FUpdateLock=0 then
end; begin
try
if FChangedDuringLock then DoChange;
except
raise GenException.Create('Exception Occured');
end;
end;
end; end;
procedure TControlSelection.SetCustomForm; procedure TControlSelection.SetCustomForm;
@ -525,12 +534,18 @@ end;
procedure TControlSelection.DoChange; procedure TControlSelection.DoChange;
begin begin
try
if (FUpdateLock>0) then if (FUpdateLock>0) then
FChangedDuringLock:=true FChangedDuringLock:=true
else begin else
if Assigned(FOnChange) then FOnChange(Self); begin
if Assigned(fOnChange) then fOnChange(Self);
FChangedDuringLock:=false; FChangedDuringLock:=false;
end; end;
except
Writeln('Exception in DoChange');
//Crashes!!!! raise GenException.Create('Exception Occured');
end;
end; end;
procedure TControlSelection.SetVisible(const Value: Boolean); procedure TControlSelection.SetVisible(const Value: Boolean);

View File

@ -174,12 +174,9 @@ Begin
Writeln('[TDesigner.RemoveControl] ',Control.Name,':',Control.ClassName); Writeln('[TDesigner.RemoveControl] ',Control.Name,':',Control.ClassName);
if Assigned(FOnRemoveComponent) then if Assigned(FOnRemoveComponent) then
FOnRemoveComponent(Self,Control); FOnRemoveComponent(Self,Control);
Writeln('[TDesigner.RemoveControl] 1');
FCustomForm.RemoveControl(TCOntrol(Control)); FCustomForm.RemoveControl(TCOntrol(Control));
//this send a message to notification and removes it from the controlselection //this send a message to notification and removes it from the controlselection
Writeln('[TDesigner.RemoveControl] 2');
FFormEditor.DeleteControl(Control); FFormEditor.DeleteControl(Control);
Writeln('[TDesigner.RemoveControl] end');
end; end;
Procedure TDesigner.NudgeControl(DiffX, DiffY : Integer); Procedure TDesigner.NudgeControl(DiffX, DiffY : Integer);
@ -693,6 +690,7 @@ procedure TDesigner.Notification(AComponent: TComponent; Operation: TOperation);
Begin Begin
if Operation = opInsert then if Operation = opInsert then
begin begin
Writeln('opInsert');
end end
else else
if Operation = opRemove then if Operation = opRemove then

View File

@ -1502,23 +1502,37 @@ end;
function TObjectInspector.ComponentToString(c:TComponent):string; function TObjectInspector.ComponentToString(c:TComponent):string;
begin begin
Try
Result:=c.GetNamePath+': '+c.ClassName; Result:=c.GetNamePath+': '+c.ClassName;
except
Result := '';
Writeln('Exception: ObjectInspector ComponentToString');
end;
end; end;
procedure TObjectInspector.AddComponentToAvailComboBox(AComponent:TComponent); procedure TObjectInspector.AddComponentToAvailComboBox(AComponent:TComponent);
var Allowed:boolean; var Allowed:boolean;
begin begin
try
Allowed:=true; Allowed:=true;
if Assigned(FOnAddAvailableComponent) then if Assigned(FOnAddAvailableComponent) then
FOnAddAvailableComponent(AComponent,Allowed); FOnAddAvailableComponent(AComponent,Allowed);
if Allowed then if Allowed then
AvailCompsComboBox.Items.AddObject( AvailCompsComboBox.Items.AddObject(
ComponentToString(AComponent),AComponent); ComponentToString(AComponent),AComponent);
except
Writeln('Exception: ObjectInspector AddComponentToAvailComboBox');
end;
end; end;
procedure TObjectInspector.PropEditLookupRootChange; procedure TObjectInspector.PropEditLookupRootChange;
begin begin
try
FillComponentComboBox; FillComponentComboBox;
except
Writeln('Exception: ObjectInspector PropEditLookupRootCHange');
end;
end; end;
procedure TObjectInspector.FillComponentComboBox; procedure TObjectInspector.FillComponentComboBox;
@ -1528,6 +1542,7 @@ var a:integer;
begin begin
//writeln('[TObjectInspector.FillComponentComboBox] A ',FUpdatingAvailComboBox //writeln('[TObjectInspector.FillComponentComboBox] A ',FUpdatingAvailComboBox
//,' ',FPropertyEditorHook<>nil,' ',FPropertyEditorHook.LookupRoot<>nil); //,' ',FPropertyEditorHook<>nil,' ',FPropertyEditorHook.LookupRoot<>nil);
try
if FUpdatingAvailComboBox then exit; if FUpdatingAvailComboBox then exit;
FUpdatingAvailComboBox:=true; FUpdatingAvailComboBox:=true;
AvailCompsComboBox.Items.BeginUpdate; AvailCompsComboBox.Items.BeginUpdate;
@ -1551,6 +1566,9 @@ begin
AvailCompsComboBox.Text:=''; AvailCompsComboBox.Text:='';
end else end else
AvailCompsComboBox.ItemIndex:=a; AvailCompsComboBox.ItemIndex:=a;
except
Writeln('Exception: ObjectInspector FillComponentComboBox');
end;
end; end;
procedure TObjectInspector.SetSelections( procedure TObjectInspector.SetSelections(

View File

@ -2865,10 +2865,14 @@ end;
procedure TPropertyEditorHook.SetLookupRoot(AComponent:TComponent); procedure TPropertyEditorHook.SetLookupRoot(AComponent:TComponent);
begin begin
try
if FLookupRoot=AComponent then exit; if FLookupRoot=AComponent then exit;
FLookupRoot:=AComponent; FLookupRoot:=AComponent;
if Assigned(FOnChangeLookupRoot) then if Assigned(FOnChangeLookupRoot) then
FOnChangeLookupRoot(); FOnChangeLookupRoot();
except
Writeln('Exception in PropEdits.pp SetLookupRoot');
end;
end; end;

View File

@ -523,16 +523,24 @@ end;
procedure TCustomFormEditor.SetSelectedComponents( procedure TCustomFormEditor.SetSelectedComponents(
TheSelectedComponents : TComponentSelectionList); TheSelectedComponents : TComponentSelectionList);
begin begin
if FSelectedComponents.Count>0 then begin try
if FSelectedComponents[0].Owner<>nil then begin if FSelectedComponents.Count>0 then
Obj_Inspector.PropertyEditorHook.LookupRoot:= begin
FSelectedComponents[0].Owner; if FSelectedComponents[0].Owner<>nil then
end else begin begin
Obj_Inspector.PropertyEditorHook.LookupRoot:= FSelectedComponents[0].Owner;
end
else
begin
Obj_Inspector.PropertyEditorHook.LookupRoot:=FSelectedComponents[0]; Obj_Inspector.PropertyEditorHook.LookupRoot:=FSelectedComponents[0];
end; end;
end; end;
FSelectedComponents.Assign(TheSelectedComponents); FSelectedComponents.Assign(TheSelectedComponents);
Obj_Inspector.Selections := FSelectedComponents; Obj_Inspector.Selections := FSelectedComponents;
except
Writeln('Exception in CustomFormEditor SetSelectedComponents');
end;
end; end;
Function TCustomFormEditor.AddSelected(Value : TComponent) : Integer; Function TCustomFormEditor.AddSelected(Value : TComponent) : Integer;