Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

SetFrameDef for SheetObjects doesn't work - AxQlikOCX COM API

Hey, tried to set a Texts of a SheetObject of a qvw file via the AxQlikOCX COM API.

It worked for Text of TextBoxes, and for Values of Variables but it didn't work with FrameDef Properties like the Position Rect and the HelpText.

It is the SetFrameDef Method that does work. If Properties are set with the SetProperties Method, like the Text of the Textbox, then it works.

I wrote some minimal tests to demonstrate:

Setting the HelpText with SetFrameDef fails:

[TestMethod]

public void TestSetFrameDefHelpText() {

     AxQlikOCX = qlikViewOcxForm.AxQlikOCX;

     String filePath = "C:\\MyLittleQvw.qvw";

     Doc document = AxQlikOCX.OpenDocument(filePath);

     SheetObject tx2229 = document.GetSheetObject("TX2229");

     IFrame frameDef = tx2229.GetFrameDef();

     String oldHelpText = frameDef.HelpText.v;

     String newHelpText = "I am the new Helptext!";

     frameDef.HelpText.v = newHelpText;

     Assert.AreEqual(newHelpText, frameDef.HelpText.v); // Succeeds, IFrame object changed correctly

     tx2229.SetFrameDef(frameDef);

     document.Save();

     tx2229 = document.GetSheetObject("TX2229");

     frameDef = tx2229.GetFrameDef();

     Assert.AreEqual(newHelpText, frameDef.HelpText.v); // Fails

}

Setting the Rect Top with SetFrameDef fails:

[TestMethod]

public void TestSetFrameDefTop() {

     AxQlikOCX = qlikViewOcxForm.AxQlikOCX;

     String filePath = "C:\\MyLittleQvw.qvw";

     Doc document = AxQlikOCX.OpenDocument(filePath);

     SheetObject tx2229 = document.GetSheetObject("TX2229");

     IFrame frameDef = tx2229.GetFrameDef();

     IRect oldRect = frameDef.Rect;

     int newTop = 777;

     oldRect.Top = newTop;

     Assert.AreEqual(newTop, oldRect.Top); // Succeeds, IRect object changed correctly

     tx2229.SetFrameDef(frameDef);

     document.Save();

     tx2229 = document.GetSheetObject("TX2229");

     frameDef = tx2229.GetFrameDef();

     Assert.AreEqual(newTop, frameDef.Rect.Top); // Fails

}

Setting the Text of a TextBox with SetProperties succeeds:

[TestMethod]

public void TestSetPropertiesText() {

     AxQlikOCX = qlikViewOcxForm.AxQlikOCX;

     String filePath = "C:\\MyLittleQvw.qvw";

     Doc document = AxQlikOCX.OpenDocument(filePath);

     TextObject tx2229 = document.GetSheetObject("TX2229") as TextObject;

     ITextObjectProperties textObjectProperties = tx2229.GetProperties();

     String oldText = textObjectProperties.Layout.Text.v;

     // by the way, the API says the "Text" Property is found in ITextObjectProperties but it is in ITextObjectProperties.Layout!

     String newText = "I am the new Text";

     textObjectProperties.Layout.Text.v = newText;

     Assert.AreEqual(newText, textObjectProperties.Layout.Text.v); // Succeeds

     tx2229.SetProperties(textObjectProperties);

     document.Save();

     tx2229 = document.GetSheetObject("TX2229") as TextObject;

     textObjectProperties = tx2229.GetProperties();

     Assert.AreEqual(newText, textObjectProperties.Layout.Text.v); // Succeeds

}

1 Solution

Accepted Solutions
Not applicable
Author

I solved it. Like I said, the SetFrameDef does not work. It's absolutely ridiculous, that this method even exist, because you find it a lot faster, then the working method to set the IFrame Property.

It is possible to set the IFrame properties through the SetProperties Method. This Method is only visible in the concrete classes like TextObject, so you have to cast the SheetObject first. With GetProperties you get for example the ITextObjectProperties object. In there you get the IFrame object in Layout.Frame. After changing the Attributes of this object, you can set it with the SetProperties Method.

The code below changes the HelpText

[TestMethod]

        public void TestSetPropertiesLayoutFrameHelpText()

        {

            AxQlikOCX = qlikViewOcxForm.AxQlikOCX;

            String filePath = "C:\\MyLittleQvw.qvw";

            Doc document = AxQlikOCX.OpenDocument(filePath);

            TextObject tx2229 = document.GetSheetObject("TX2229") as TextObject;

            ITextObjectProperties textObjectProperties = tx2229.GetProperties();

            String oldHelpText = textObjectProperties.Layout.Frame.HelpText.v;

            String newHelpText = "I am the new Helptext!";

            textObjectProperties.Layout.Frame.HelpText.v = newHelpText;

            Assert.AreEqual(newHelpText, textObjectProperties.Layout.Frame.HelpText.v);  // Succeeds

            tx2229.SetProperties(textObjectProperties);

            document.Save();

            tx2229 = document.GetSheetObject("TX2229") as TextObject;

            textObjectProperties = tx2229.GetProperties();

            Assert.AreEqual(newHelpText, textObjectProperties.Layout.Frame.HelpText.v);  // Succeeds, Hurray

        }

View solution in original post

1 Reply
Not applicable
Author

I solved it. Like I said, the SetFrameDef does not work. It's absolutely ridiculous, that this method even exist, because you find it a lot faster, then the working method to set the IFrame Property.

It is possible to set the IFrame properties through the SetProperties Method. This Method is only visible in the concrete classes like TextObject, so you have to cast the SheetObject first. With GetProperties you get for example the ITextObjectProperties object. In there you get the IFrame object in Layout.Frame. After changing the Attributes of this object, you can set it with the SetProperties Method.

The code below changes the HelpText

[TestMethod]

        public void TestSetPropertiesLayoutFrameHelpText()

        {

            AxQlikOCX = qlikViewOcxForm.AxQlikOCX;

            String filePath = "C:\\MyLittleQvw.qvw";

            Doc document = AxQlikOCX.OpenDocument(filePath);

            TextObject tx2229 = document.GetSheetObject("TX2229") as TextObject;

            ITextObjectProperties textObjectProperties = tx2229.GetProperties();

            String oldHelpText = textObjectProperties.Layout.Frame.HelpText.v;

            String newHelpText = "I am the new Helptext!";

            textObjectProperties.Layout.Frame.HelpText.v = newHelpText;

            Assert.AreEqual(newHelpText, textObjectProperties.Layout.Frame.HelpText.v);  // Succeeds

            tx2229.SetProperties(textObjectProperties);

            document.Save();

            tx2229 = document.GetSheetObject("TX2229") as TextObject;

            textObjectProperties = tx2229.GetProperties();

            Assert.AreEqual(newHelpText, textObjectProperties.Layout.Frame.HelpText.v);  // Succeeds, Hurray

        }