auraham
auraham

Reputation: 1741

how can I send a message to a form using a dll?

I am developing an gui application in c# that uses a dll. This dll contains several common functions, like validation of properties.

However, I need to validate the properties of an object with a function like this:

public static bool validate(MyObject object)
{

  bool success = true;

  // some validation
  if(!valid(object.property))
  {
    // log to database, this works
    log("property is not valid"); // log to database, this works

    // how can I do this?
    sendMessageToForm("property is not valid");

    success = false;
  }

  return success;

}

Additionally, validate() must return a boolean value, not a string of messages

how can I send a message to a form through a dll?

Upvotes: 0

Views: 381

Answers (3)

Luke Narramore
Luke Narramore

Reputation: 509

public static bool validate(MyObject object, out message)

That will give you an output message string that can be set from where validate is called.

Upvotes: 0

Andrei G
Andrei G

Reputation: 1590

If what you have shown here is the code inside your dll, I'm assuming you want to update the form from inside your dll. The way to do that is for your dll class to publish an event, let's say ValidationError event, that will also carry with it as EventArgs the message you want to display on the form.

Then, on your form, where you instantiate the object from your dll class, you would also have to attach a listener for that event.

MyClassInDll myObject=new MyClassInDll();
myObject.ValidationError+=new EventHandler<ValidationErrorMessage>(YourMethodThatDisplaysTheMessagesOnTheForm);

Then you can use the object to call if (myObject.Validate(someOtherObject)) which will return a boolean, while still triggering the event that sends the error messages to your form.

Upvotes: 0

Mulesoft Developer
Mulesoft Developer

Reputation: 2814

You need to add the reference of the dll in your project after that add the namespace of the dll in your class later on declare the object of the class and call the validate message and pass the parameter for validate.

Upvotes: 0

Related Questions