Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom functions with more than 1 argument are not called #369

Open
HugoRoss opened this issue Sep 27, 2020 · 2 comments
Open

Custom functions with more than 1 argument are not called #369

HugoRoss opened this issue Sep 27, 2020 · 2 comments

Comments

@HugoRoss
Copy link

HugoRoss commented Sep 27, 2020

Custom functions with more than 1 argument are never executed, or the argument delimiter is too hard to guess. I tried ",", ";", ", ", "; ", "|", "| "). (I would expect that at least the 1st 4 delimiters would work.)

E.g. if I call my custom function TryOut with =TryOut(A1), everything is fine. Do I call it with =TryOut(A1, ",") the function is never called. I also noticed that all examples of custom functions are only with one argument, but the interface is clearly made for multiple arguments as they are returned as object[].

To Reproduce

  1. Define a class with a custom function:
#nullable enable

using unvell.ReoGrid;

namespace BugReport {

    public static partial class FormulaCollection {

        public static object? TryOut(Cell cell, object[] args) {
            if (args is null) return "Called with null";
            if (args.Length == 0) return "Called with empty";
            if (args.Length == 1) return "Called with 1 arg";
            return $"Called with {args.Length} args!";
        }

    }

}
  1. Create a Form that has a ReoGridControl and that registers the custom function with name TryOut:
using System.Windows.Forms;
using f = BugReport.FormulaCollection;

namespace BugReport {

    public partial class SpreadSheet : Form {

        public SpreadSheet() {
            InitializeComponent();
            unvell.ReoGrid.Formula.FormulaExtension.CustomFunctions[nameof(f.TryOut)] = f.TryOut;
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            reoGridControl1 = new unvell.ReoGrid.ReoGridControl();
            SuspendLayout();
            // 
            // reoGridControl1
            // 
            reoGridControl1.BackColor = System.Drawing.Color.White;
            reoGridControl1.ColumnHeaderContextMenuStrip = null;
            reoGridControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            reoGridControl1.LeadHeaderContextMenuStrip = null;
            reoGridControl1.Location = new System.Drawing.Point(0, 0);
            reoGridControl1.Name = "reoGridControl1";
            reoGridControl1.RowHeaderContextMenuStrip = null;
            reoGridControl1.Script = null;
            reoGridControl1.SheetTabContextMenuStrip = null;
            reoGridControl1.SheetTabNewButtonVisible = true;
            reoGridControl1.SheetTabVisible = true;
            reoGridControl1.SheetTabWidth = 60;
            reoGridControl1.ShowScrollEndSpacing = true;
            reoGridControl1.Size = new System.Drawing.Size(800, 450);
            reoGridControl1.TabIndex = 0;
            reoGridControl1.Text = "SpreadSheet";
            // 
            // SpreadSheet
            // 
            AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            ClientSize = new System.Drawing.Size(800, 450);
            Controls.Add(reoGridControl1);
            Name = "SpreadSheet";
            Text = "SpreadSheetForm";
            ResumeLayout(false);

        }

        private unvell.ReoGrid.ReoGridControl reoGridControl1;

    }

}
  1. Modify the entry point to use the form:
using System;
using System.Windows.Forms;

namespace BugReport {

    static class Program {

        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new SpreadSheet());
        }

    }

}
  1. Start the application and type in any cell
  • =TryOut() -> Works, the function is called and returns Called with empty!.
  • =TryOut("Foo") -> Works, the function is called and returns Called with 1 arg!.
  • =TryOut("Foo", "Bar") -> Does not work, the function is never called, the cell remains empty.
  • =TryOut("Foo"; "Bar") -> Does not work, the function is never called, the cell remains empty.
  • =TryOut("Foo","Bar") -> Does not work, the function is never called, the cell remains empty.
  • =TryOut("Foo";"Bar") -> Does not work, the function is never called, the cell remains empty.

Edition
Which edition of ReoGrid do you using?

  • [X] Windows Form
  • [ ] WPF
  • [ ] Android

Environment:

  • Windows 10 (1903, Enterprise Edition)
  • Language of OS: English, Regional Settings "de-CH" with user override.

Additional context
n/a

@yamidcelta
Copy link

Look here, the same error was described, but with IF function.
I take each comma separated by one space, i.e. =TryOut(A1[space],[space]",") ---> =TryOut(A1 , ",")

@jingwood
Copy link
Member

jingwood commented Apr 3, 2021

Thanks @HugoRoss! The problem has been fixed now (#392). You can use the latest source code or wait for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants