ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

warning C4700: uninitialized local variable 'pMyObject' used

5 REPLIES 5
Reply
Message 1 of 6
ZK_BUDiKOM
938 Views, 5 Replies

warning C4700: uninitialized local variable 'pMyObject' used

It is correct?:

 

...
double radius; radius = 55.78; AcGePoint3d centerPt(0.0, 0.0, 0.0); AcDbCircle* pCircle = new AcDbCircle(centerPt,AcGeVector3d::kZAxis,radius); ACX_SetProp* pMyObject; pMyObject->setColor(pCircle, 2);
...

 

My CLASS:

class ACX_SetProp : public CObject
{
private:
AcDbEntity myObj;
public:
ACX_SetProp(); // konstruktor
~ACX_SetProp(); // destruktor
// color object
void setColor(AcDbEntity* pObject, short myColorIndex)
{
_color = myColorIndex;
AcCmColor cColor;
cColor.setColorIndex(myColorIndex);
pObject->setColor(cColor);
pObject->close();
}
protected:
int _color;
};

 

 

because I have an error message:

warning C4700: uninitialized local variable 'pMyObject' used

 

When run AutoCAD, then crash program.

 

I greet

5 REPLIES 5
Message 2 of 6
owenwengerd
in reply to: ZK_BUDiKOM

pMyObject is not initialized. Did you intend to create an ACX_SetProp object on the stack, perhaps? If not, you need to initialize pMyObject to point to an ACX_SetProp object before you use it.

--
Owen Wengerd
ManuSoft
Message 3 of 6
ZK_BUDiKOM
in reply to: owenwengerd

Hi Owen,

 

thank you for your advice 🙂

I've rebuilt my class (mytest.h):

//**  My Class **//
class C_ACX_SetProp : public CObject
{

public:
	C_ACX_SetProp();
	~C_ACX_SetProp();

	short myColorIndex() const;
	static void setColorObj(AcDbEntity* pObject, short myColorIndex);
	static void setRGBColor(AcDbEntity* pObject, Adesk::UInt8 red, Adesk::UInt8 green, Adesk::UInt8 blue);
	static void setLineWeight(AcDbEntity* pObject, AcDb::LineWeight myLineWeight);
	static void setLayer(AcDbEntity* pObject, CString myLayer);
	static void setLineType(AcDbEntity* pObject, CString myLayer);
	static void setLineTypeScale(AcDbEntity* pObject, double myScale);
	static void setVisibility(AcDbEntity* pObject, AcDb::Visibility myVisibility);
	static void setTransparency(AcDbEntity* pObject, Adesk::UInt8 alphaPercent);

};

 and now method (mytest.cpp):

C_ACX_SetProp::C_ACX_SetProp(){}
C_ACX_SetProp::~C_ACX_SetProp(){}

void C_ACX_SetProp::setColorObj(AcDbEntity* pObject, short myColorIndex)
{
		AcCmColor cColor;
		cColor.setColorIndex(myColorIndex);
		pObject->setColor(cColor);
		pObject->close();
}

void C_ACX_SetProp::setRGBColor(AcDbEntity* pObject, Adesk::UInt8 red, Adesk::UInt8 green, Adesk::UInt8 blue)
{
		AcCmColor cColor; 
		cColor.setRGB(red, green, blue);
		pObject->setColor(cColor, 1);
		pObject->close();
}

void C_ACX_SetProp::setLineWeight(AcDbEntity* pObject, AcDb::LineWeight myLineWeight)
{
		pObject->setLineWeight(myLineWeight, true);
		pObject->close();
}

void C_ACX_SetProp::setLayer(AcDbEntity* pObject, CString myLayer)
{
		pObject->setLayer(myLayer, 1, false);
		pObject->close();
}

void C_ACX_SetProp::setLineType(AcDbEntity* pObject, CString myLayer)
{
		pObject->setLinetype(myLayer, 1);
		pObject->close();
}

void C_ACX_SetProp::setLineTypeScale(AcDbEntity* pObject, double myScale)
{
		pObject->setLinetypeScale(myScale, 1);
		pObject->close();
}

void C_ACX_SetProp::setVisibility(AcDbEntity* pObject, AcDb::Visibility myVisibility)
{
		pObject->setVisibility(myVisibility, 1);
		pObject->close();
}

void C_ACX_SetProp::setTransparency(AcDbEntity* pObject, Adesk::UInt8 alphaPercent)
{
		AcCmTransparency trans;
		trans.setAlpha(alphaPercent);

		Acad::ErrorStatus es;
		es = pObject->setTransparency(trans, 1);
		if (es == Acad::eOk) {
			acutPrintf(_T("\nOK!"));
			pObject->close();
		} else {
			acutPrintf(_T("\nNot OK!"));
			pObject->close();
		}
}

and finally (mytest.cpp)::

void goTest()
{
	C_ACX_SetProp* pMyObject;
	ads_name en;
	ads_point pt;
	AcDbObject* pObj;		
	AcDbEntity* pEnt;		
	if (acedEntSel(_T("\nSelect an entity: "), en, pt) == RTNORM) {
		AcDbObjectId eId = AcDbObjectId::kNull;
		acdbGetObjectId(eId, en);

		if (Acad::eOk == acdbOpenObject(pObj, eId, AcDb::kForWrite))
		{
			pMyObject->setColorObj(pEnt, 2);
pMyObject->setLineWeight(pEnt, AcDb::kLnWt120);
pMyObject->setLineTypeScale(pEnt, 4.5); acutPrintf(_T("(%s)\n"), pEnt->isA()->name()); pEnt->close(); pObj->close(); } } }

 

No error, no crash. But this code was written correctly?

 

I greet,

Zbyszek

 

Message 4 of 6
owenwengerd
in reply to: ZK_BUDiKOM

Your code is still declaring pMyObject, but never initializing it. The only difference is no more crash because your calls to static members do not use the uninitialized pointer.

--
Owen Wengerd
ManuSoft
Message 5 of 6
ZK_BUDiKOM
in reply to: owenwengerd

"Your code is still declaring pMyObject, but never initializing it. The only difference is no more crash because your calls to static members do not use the uninitialized pointer."

 

hmmm... 😞

what I shoud to change (.h)?

class C_ACX_SetProp : public CObject
{
public:
C_ACX_SetProp();
~C_ACX_SetProp();
short myColorIndex() const;
static void setColorObj(AcDbEntity* pObject, short myColorIndex);
}

 (.cpp):

void C_ACX_SetProp::setColorObj(AcDbEntity* pObject, short myColorIndex)
{
		AcCmColor cColor;
		cColor.setColorIndex(myColorIndex);
		pObject->setColor(cColor);
		pObject->close();
}

 it is wrong here... as will properly?

static void setColorObj(AcDbEntity* pObject, short myColorIndex);

I want to write class to change possible properties selected object.

 

Checking possibilities I  had not written yet eg. exist Layer.

 

 

I greet,

Zbyszek

Message 6 of 6
owenwengerd
in reply to: ZK_BUDiKOM

It's not clear what you are trying to do, but it seems you are trying to write ObjectARX code without a fundamental understanding of C++. You may get more help if you post on a generic C++ forum and explain that you are learning. In any case, I think you must learn to walk before you ask how to run.

--
Owen Wengerd
ManuSoft

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost