{
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
In essence, what I am trying to do is combine these two methods into ONE method that handles the different kinds of objects. In this case, adding text to either Group or Flow.
(NOTE: These two methods work just fine, and they pretty much differ ONLY in the kind of object being passed in!! That is why I want to merge them!)!:
private void AddTextToGroup(ref IGroup tempGroup, string TextToAdd, int Relative_Width, Infragistics.Documents.Graphics.Font f, Infragistics.Documents.Graphics.Brush b, bool ApplyBold, bool ApplyItalic, bool ApplyUnderline) { Infragistics.Documents.Report.Text.IText tempText = tempGroup.AddText(); 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; tempText.AddContent(TextToAdd); tempGroup.Width = new RelativeWidth(Relative_Width); } private void AddTextToFlow(ref Infragistics.Documents.Report.Flow.IFlow tempFlow, string TextToAdd, Infragistics.Documents.Graphics.Font f, Infragistics.Documents.Graphics.Brush b, bool ApplyBold, bool ApplyItalic, bool ApplyUnderline) { Infragistics.Documents.Report.Text.IText tempText = tempFlow.AddText(); 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; tempText.AddContent(TextToAdd); }
The call to the method works if I do THIS:
AddTextToDocumentObject(ref a, "Notice we call this section of the Financial Health Meter, Credit Card Debt. They key term is “debt”. Credit cards are not the problem. Carrying balances on these accounts is the problem. Credit card interest is calculated monthly based on your balance.", 100, BodyFont, BodyBrush, false, false, false);
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!
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.
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); } }
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.
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.