{
Infragistics.Documents.Report.Text.IText tempText = null;
}
tempText.Style.Font.Bold = ApplyBold;
tempText.Style.Font.Italic = ApplyItalic;
tempText.Style.Font.Underline = ApplyUnderline;
tempText.AddContent(TextToAdd);
I want to be able to pass in different KINDS of Infragistics objects, like Group or Flow objects, and "Add Text" to those objects.
But when I try to call the above, I get an error:
Error: A ref or out argument must be an assignable
Oh well. =)
I want to thank you, and Matt, for your time spent. You have really helped me get out of a few tough spots and have filled some gaps in my understanding of how the Infragistics document engine works.
There is no common base interface/class that has the members that you are using - actually there is no base interface for the interfaces you sited. I think the approach you took is fine.
Do all of the Infragistics Document "classes" have a common ancestor?
I want to be able to pass either an IGroup or IFlow or ISite into the SAME method and be able to add Text to them.
I am not sure if I have gone about it the most effective way.
While the following code works -- I just wonder if I am doing it "right":
//Call to the method with an IGroupobject qg = (object)QuoteGroup;AddTextToDocumentObject(ref qg, phrQuoteOne.InternalText, 80, QuoteFont, QuoteBrush, true, false, false, 0, 0, false); //Call to the method with an IFlowobject f = (object)flow;AddTextToDocumentObject(ref f, phrWhatIsDebtSubHeading.InternalText, 100, SubHeadingFont, SubHeadingBrush, true, false, false, 0, 0, false);
private void AddTextToDocumentObject(ref object tempObj, string TextToAdd, int Relative_Width, Infragistics.Documents.Graphics.Font f, Infragistics.Documents.Graphics.Brush b, bool ApplyBold, bool ApplyItalic, bool ApplyUnderline, int SiteLeftPos, int SiteTopPos, bool SupportRichText) { Infragistics.Documents.Report.Text.IText tempText = null;
CallAddTextForDocumentObject(ref tempObj, ref tempText, SiteLeftPos, SiteTopPos);
tempText.Style = new Infragistics.Documents.Report.Text.Style(f, b); tempText.Style.Font.Bold = ApplyBold; tempText.Style.Font.Italic = ApplyItalic; tempText.Style.Font.Underline = ApplyUnderline; if (SupportRichText == false) { tempText.AddContent(TextToAdd); } else { tempText.AddRichContent(TextToAdd); }
if (tempObj is Infragistics.Documents.Report.IGroup) { ((Infragistics.Documents.Report.IGroup)tempObj).Width = new RelativeWidth(Relative_Width); } if (tempObj is Infragistics.Documents.Report.Flow.IFlow) { ((Infragistics.Documents.Report.Flow.IFlow)tempObj).Width = new RelativeWidth(Relative_Width); } }
public void CallAddTextForDocumentObject(ref object tempObj, ref Infragistics.Documents.Report.Text.IText tempText, int SiteLeftPos, int SiteTopPos) {
if (tempObj is Infragistics.Documents.Report.IGroup) { tempText = ((Infragistics.Documents.Report.IGroup)tempObj).AddText(); } if (tempObj is Infragistics.Documents.Report.Flow.IFlow) { tempText = ((Infragistics.Documents.Report.Flow.IFlow)tempObj).AddText(); } if (tempObj is Infragistics.Documents.Report.ISite) { tempText = ((Infragistics.Documents.Report.ISite)tempObj).AddText(SiteLeftPos, SiteTopPos); } }
I would think that simply removing the "ref" from the parameter in your original AddTextToDocumentObject code should work fine. The only reason you had to downcast to an object is because a by ref parameter can only accept a value of that type.
Andrew Smith"] There is no need to pass the tempObj parameter by reference. You would only need to do that if the parameter were going to be replaced within that method or if the object that you would be manipulating were a valuetype (e.g. struct). Since both of the objects that you are passing are reference types, passing them by value is sufficient since it is the pointer to the object that is being passed by value and not the object itself.
There is no need to pass the tempObj parameter by reference. You would only need to do that if the parameter were going to be replaced within that method or if the object that you would be manipulating were a valuetype (e.g. struct). Since both of the objects that you are passing are reference types, passing them by value is sufficient since it is the pointer to the object that is being passed by value and not the object itself.
Okay
Is it necesary to cast the IGroup (or IFlow) object to an "object" before passing it in. I need a method that can accept either an IFlow or an IGroup object.
object a = (object)WhyIsGroup;
Some sample code on how to do this the right way would be very helpful!