How is possible to return a value from a Form into a Codeun?

efassettaefassetta Member Posts: 53
Hello, i need help. I have a Codeunit that runs a Form (with Form.RUN function). On this Form i have a text variable to modify. Then when i close the form, i need this value in the Codeunit.

How can i do??

Thank's in advance.

Comments

  • krikikriki Member, Moderator Posts: 9,118
    edited 2006-03-15
    global variable:
    frmMyForm Form "My Form"
    clear(frmMyForm);
    IF frmMyForm.RUNMODAL = ACTION::LookupOk THEN BEGIN
      MESSAGE('%1',frmMyForm.GetReturnValue());
    END;
    
    Of course you have to create a lookup-ok button if you don't have it(copy the Ok button from Form 4) and if you add the cancel-button, you can also cancel the action and you wont see the message.

    In the form, you have to create this function:
    GetReturnValue() : (return-type is the type of your variable)
    BEGIN
      EXIT("My Variable");
    END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,118
    The previous example works fine in case of a form based on a table.

    The following code is in case you don't have a table:
    OBJECT Form 99000 The Form
    {
      OBJECT-PROPERTIES
      {
        Date=15/03/06;
        Time=18:53:51;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=9790;
        Height=6710;
        TableBoxID=1000000000;
      }
      CONTROLS
      {
        { 1000000003;CommandButton;2530;5940;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Default=Yes;
                                                     PushAction=OK;
                                                     InvalidActionAppearance=Hide }
        { 1000000004;CommandButton;4950;5940;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Cancel=Yes;
                                                     PushAction=Cancel;
                                                     InvalidActionAppearance=Hide }
        { 1000000005;CommandButton;7370;5940;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     PushAction=FormHelp }
        { 1000000000;TextBox;4070 ;990  ;1700 ;440  ;SourceExpr=codText }
        { 1000000001;Label  ;660  ;990  ;3300 ;440  ;ParentControl=1000000000 }
      }
      CODE
      {
        VAR
          codText@1000000000 : Code[10];
    
        PROCEDURE GetReturnValue@1000000001() : Code[10];
        BEGIN
          EXIT(codText);
        END;
    
        BEGIN
        END.
      }
    }
    
    OBJECT Codeunit 99000 The Codeunit
    {
      OBJECT-PROPERTIES
      {
        Date=15/03/06;
        Time=18:54:19;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                CLEAR(frmTheForm);
                IF frmTheForm.RUNMODAL = ACTION::OK THEN BEGIN
                  MESSAGE('<%1>',frmTheForm.GetReturnValue());
                END;
              END;
    
      }
      CODE
      {
        VAR
          frmTheForm@1000000000 : Form 99000;
    
        BEGIN
        END.
      }
    }
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,118
    :oops:
    there is also a how to for it : http://www.mibuso.com/howtoinfo.asp?FileID=7
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • SavatageSavatage Member Posts: 7,142
    I think you covered all the bases =D>
Sign In or Register to comment.