mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 09:55:53 +02:00
fpvectorial: Fixes a crash caused by an uninitialized variable in the block search. Moved the block search to a separate function to make the code reusable and more clear.
git-svn-id: trunk@39632 -
This commit is contained in:
parent
c7d3e19290
commit
b6a578c647
@ -934,7 +934,7 @@ procedure TvDXFVectorialReader.ReadENTITIES(ATokens: TDXFTokens; AData: TvVector
|
||||
var
|
||||
i: Integer;
|
||||
CurToken: TDXFToken;
|
||||
lEntity: TvEntity;
|
||||
lEntity: TvEntity; // only to help debugging
|
||||
begin
|
||||
IsReadingPolyline := False;
|
||||
|
||||
@ -1417,11 +1417,11 @@ var
|
||||
lName: string;
|
||||
lBlock: TvBlock;
|
||||
PosX, PosY, PosZ: Double;
|
||||
lCurEntity: TvEntity;
|
||||
begin
|
||||
PosX := 0.0;
|
||||
PosY := 0.0;
|
||||
PosZ := 0.0;
|
||||
Result := nil;
|
||||
|
||||
for i := 0 to ATokens.Count - 1 do
|
||||
begin
|
||||
@ -1443,15 +1443,7 @@ begin
|
||||
end;
|
||||
|
||||
// Find the block by its name
|
||||
for i := 0 to AData.GetEntitiesCount()-1 do
|
||||
begin
|
||||
lCurEntity := AData.GetEntity(i);
|
||||
if (lCurEntity is TvBlock) and (TvBlock(lCurEntity).Name = lName) then
|
||||
begin
|
||||
lBlock := TvBlock(lCurEntity);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
lBlock := TvBlock(AData.FindEntityWithNameAndType(lName, TvBlock));
|
||||
if lBlock = nil then Exit;
|
||||
|
||||
// write the data
|
||||
|
@ -211,6 +211,7 @@ type
|
||||
TvEntity = class
|
||||
public
|
||||
X, Y, Z: Double;
|
||||
Name: string;
|
||||
constructor Create; virtual;
|
||||
procedure Clear; virtual;
|
||||
// in CalculateBoundingBox always remember to treat correctly the case of ADest=nil!!!
|
||||
@ -228,6 +229,8 @@ type
|
||||
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
|
||||
end;
|
||||
|
||||
TvEntityClass = class of TvEntity;
|
||||
|
||||
{ TvEntityWithPen }
|
||||
|
||||
TvEntityWithPen = class(TvEntity)
|
||||
@ -526,7 +529,6 @@ type
|
||||
protected
|
||||
FElements: TFPList; // of TvEntity
|
||||
public
|
||||
Name: string;
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
//
|
||||
@ -547,7 +549,6 @@ type
|
||||
TvInsert = class(TvEntity)
|
||||
public
|
||||
Block: TvBlock; // The block to be inserted
|
||||
Name: string;
|
||||
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0;
|
||||
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
||||
end;
|
||||
@ -627,6 +628,7 @@ type
|
||||
function GetEntitiesCount: Integer;
|
||||
function GetLastEntity(): TvEntity;
|
||||
function FindAndSelectEntity(Pos: TPoint): TvFindEntityResult;
|
||||
function FindEntityWithNameAndType(AName: string; AType: TvEntityClass): TvEntity;
|
||||
{ Data removing methods }
|
||||
procedure Clear; virtual;
|
||||
function DeleteEntity(AIndex: Cardinal): Boolean;
|
||||
@ -2657,6 +2659,24 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TvVectorialPage.FindEntityWithNameAndType(AName: string;
|
||||
AType: TvEntityClass): TvEntity;
|
||||
var
|
||||
i: Integer;
|
||||
lCurEntity: TvEntity;
|
||||
begin
|
||||
Result := nil;
|
||||
for i := 0 to GetEntitiesCount()-1 do
|
||||
begin
|
||||
lCurEntity := GetEntity(i);
|
||||
if (lCurEntity is AType) and (lCurEntity.Name = AName) then
|
||||
begin
|
||||
Result := lCurEntity;
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TvVectorialPage.Clear;
|
||||
begin
|
||||
FEntities.ForEachCall(CallbackDeleteEntity, nil);
|
||||
|
Loading…
Reference in New Issue
Block a user