Desktop productivity for business analysts and programmers

How do I add a SAS editor control to my Custom Task for code preview

Reply
N/A
Posts: 0

How do I add a SAS editor control to my Custom Task for code preview

Hi every one,

I am building a custom Task, and I would like to add a SAS editor control for code preview in my task. What control should I use? I don’t want to use the .NET TextBox.

(When I add SAS.EG.Controls.dll to my .NET project reference and to the ToolBox, many SAS-supplied controls such as SASDatasetSelector appear, but there is no SAS editor control).

Thanks for any help,

Maurice
Community Manager
Posts: 2,889

Re: How do I add a SAS editor control to my Custom Task for code preview

Maurice,

In the examples on our web site at http://support.sas.com/eguide, there are a few tasks that show this. For example, the "SAS Catalog Explorer" and the "Simple SAS Program Editor" use the enhanced editor.

The key assemblies are SAS.AxInterop.EDITORCONTROLLib.dll and SAS.Interop.EDITORCONTROLLib.dll.

Chris
N/A
Posts: 0

Re: How do I add a SAS editor control to my Custom Task for code preview

Thanks Chris,

I downloaded the examples, AxInterop.EDITORCONTROLLib.dll and Interop.EDITORCONTROLLib.dll must be referenced.
But unlike the controls in the SAS.EG.Controls.dll, it seems not possible to add the editor control on the toolbox so that it can be drag and dropped on the form (Error message: “There are no components in ‘C:\Program Files\SAS\Enterprise Guide 4\SAS.AxInterop.EDITORCONTROLLib.dll’ that can be placed on the toolbox.”)....

Thanks,

Maurice
Community Manager
Posts: 2,889

Re: How do I add a SAS editor control to my Custom Task for code preview

In EG 4.1, the assemblies have the "SAS." prefix in their names.

I don't recommend using the designer to deal with the enhanced editor control. Instead, I would use a placeholder control (like a panel) and then dynamically create the editor control when your form is loaded.

For example, declare this:

[pre]
private AxEDITORCONTROLLib.AxEditorControl ctlEditor = null;
[/pre]

Then in OnLoad(), do this:

[pre]
ctlEditor = new AxEDITORCONTROLLib.AxEditorControl();
ctlEditor.Location = panelPlaceholder.Location;
ctlEditor.Visible = true;
ctlEditor.Dock = panelPlaceholder.Dock;

// add handler for when the control is finished being created
ctlEditor.HandleCreated += new EventHandler(ctlEditor_HandleCreated);

this.Controls.AddRange(new System.Windows.Forms.Control[] {this.ctlEditor});
[/pre]

Then be sure not to reference the control's methods until the handle is created. This is not uncommon when dealing with ActiveX controls via COM interop. It might take a moment to initialize, and you cannot call into it before it's ready.

[pre]
// control is created - now open file
private void ctlEditor_HandleCreated(object sender, EventArgs e)
{
if (file.Length>0)
ctlEditor.OpenFile(file);
ctlEditor.SetLanguage(4); // set language to SAS for syntax coloring
}
[/pre]

Chris
New Contributor
Posts: 3

Re: How do I add a SAS editor control to my Custom Task for code preview

Is there any way to utilize the Editor control as as SAS-Log control?

How to enable SAS-Log syntax-highlighting such as red error-messages? Can I use the SetLanguage method? But which integer value to set?
Community Manager
Posts: 2,889

Re: How do I add a SAS editor control to my Custom Task for code preview

If you are using EG 4.2, you can use the new SAS.Tasks.Toolkit library to simplify this.

The control you want is in SAS.Tasks.Toolkit.dll, and the control is:

SAS.Tasks.Toolkit.Controls.SASTextEditorCtl

It has a property that you can set:

ContentType = SAS.Tasks.Toolkit.Controls.SASTextEditorCtl.eContentType.SASProgram;

or

ContentType =
SAS.Tasks.Toolkit.Controls.SASTextEditorCtl.eContentType.SASLog

Chris
New Contributor
Posts: 3

Re: How do I add a SAS editor control to my Custom Task for code preview

Dear Chris,

unfortunately we are using EG 4.1. Is there another way using this version?

Thanks, Florian
Super Contributor
Super Contributor
Posts: 3,174

Re: How do I add a SAS editor control to my Custom Task for code preview

Please, in the future, create a new forum post, rather than piggy-backing on a 3 year old post from another individual -- it's realistic to paste a link to the prior post but to simply REPLY to someone else's closed post is unreasonable.

Scott Barry
SBBWorks, Inc.
Community Manager
Posts: 2,889

Re: How do I add a SAS editor control to my Custom Task for code preview

Okay, okay. The magic number is....

6

Recommend that you set the properties in this order (assuming you like your log view to be read-only):

editor.ReadOnly=true;
editor.SetLanguage(6);

Chris
Contributor
Posts: 36

Re: How do I add a SAS editor control to my Custom Task for code preview

Hello Chris

Note    I use VB 2008, Guide 4.3

I followed your instructions to insert an editor in a Cutom Task. But on a machine equiped by only Enterprise Guide, i got this error:

System.Runtime.InteropServices.COMException

Classe non enregistrée (Exception de HRESULT : 0x80040154 (REGDB_E_CLASSNOTREG))

------------------------------ Début des informations techniques------------------------------

System.Runtime.InteropServices.COMException (0x80040154): Classe non enregistrée (Exception de HRESULT : 0x80040154 (REGDB_E_CLASSNOTREG))
   à System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
   à System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
   à System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
   à System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
   à System.Windows.Forms.AxHost.CreateInstance()
   à System.Windows.Forms.AxHost.GetOcxCreate()
   à System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
   à System.Windows.Forms.AxHost.CreateHandle()
   à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   à System.Windows.Forms.Control.CreateControl()
   à System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   à System.Windows.Forms.TabPage.set_Visible(Boolean value)
   à System.Windows.Forms.TabControl.UpdateTabSelection(Boolean updateFocus)
   à System.Windows.Forms.TabControl.OnSelectedIndexChanged(EventArgs e)
   à System.Windows.Forms.TabControl.WmSelChange()
   à System.Windows.Forms.TabControl.WndProc(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Community Manager
Posts: 2,889

Re: How do I add a SAS editor control to my Custom Task for code preview

Victor,

In EG 4.3 the process is different, but even easier.  You can simply use the SAS.Tasks.Toolkit.Controls.SASTextEditorCtl class.

There are examples here:

  http://go.sas.com/customtasksapi

See the SAS Program Runner project, for example.

Also, this is described in my book: Custom Tasks for SAS Enterprise Guide using Microsoft .NET

The book features an example in Chapter 12, and the source code for that project is available here (and described in this blog post):

Custom Tasks for SAS Enterprise Guide using Microsoft .NET (Examples)

And finally, you can also see the same source code on GitHub:

cjdinger/SasDatasetToDataStep · GitHub

Specifically:

SasDatasetToDataStep/src/DS2DatalinesForm.cs at master · cjdinger/SasDatasetToDataStep · GitHub

Chris

Contributor
Posts: 36

Re: How do I add a SAS editor control to my Custom Task for code preview

This is what i finally did. It's so simple.

I should look your book more often.

Thank's any way

Ask a Question
Discussion stats
  • 11 replies
  • 727 views
  • 0 likes
  • 5 in conversation