Como trabalhar dinamicamente com TextBoxes de diálogo em dm-script

Sep 02 2020

Como faço para definir e obter o texto de um TextBoxem uma caixa de diálogo no dm-script?


Verifique a seguinte caixa de diálogo de exemplo. Ele cria um diálogo que contém um TextBox. Eu quero definir o valor disso TextBoxna criação. E eu quero modificar (obter e definir) o valor em uma chamada de função, digamos, um clique de botão.

Como mostrado no código fornecido, eu tentei DLGValue(), DLGTitle()e DLGLabel(). Mas nenhum deles funcionou. Como eu faço isso?

Nota: O botão Mostrar mostra o atual que TagGrouprepresenta o TextBox. Eu esperava ver algo, seja no estado inicial ou depois que o elemento mudou. Mas não consegui encontrar nada.

class ExampleDialog : UIFrame{
    number counter;
    TagGroup field;
    
    void addText(object self){
        string msg = "Added text the " + counter + "-th time.\n";
        string current_text = field.DLGGetStringValue();
        field.DLGValue(current_text + "Value: " + msg);
        field.DLGTitle(current_text + "Title: " + msg);
        field.DLGLabel(current_text + "Label: " + msg);
        result(msg);
        
        field.DLGInvalid(1);
        self.validateView();
        
        counter++;
    }
    
    void showTg(object self){
        field.TagGroupOpenBrowserWindow(0);
    }
    
    object init(object self){
        TagGroup dlg, dlg_items;
        
        counter = 1;
        
        dlg = DLGCreateDialog("Example", dlg_items);
        
        dlg.DLGAddElement(DLGCreatePushButton("Update", "addText"));
        dlg.DLGAddElement(DLGCreatePushButton("Show", "showTg"));
        
        field = DLGCreateTextBox(100, 10, 1);
        field.DLGValue("Value: Initial");
        field.DLGTitle("Title: Initial");
        field.DLGLabel("Label: Initial");
        dlg.DLGAddElement(field);
        
        self.super.init(dlg);
        return self;
    }
}

alloc(ExampleDialog).init().pose();

Respostas

1 BmyGuest Sep 02 2020 at 20:26

Isso vai fazer:


    class handler : UIFrame {
        void ShowText( object self ) {
            string str = self.GetTextElementData("textBox");
            result( "text box :[" + str + "]\n");
            return;
        };
        void SetText( object self ) {
            string str = ""
            for(number i=0;i<100;i++) str+=CHR(64+Random()*26);
            self.SetTextElementData("textBox",str);
            return;
        };
    };
    
    number boxWidth = 40, boxHeight = 4, txtLength = 160;
    
    TagGroup Dialog = DLGCreateDialog( "text box");
    TagGroup txtScript = DLGCreateTextBox( boxWidth, BoxHeight, txtLength ).DLGIdentifier( "textBox" );
    TagGroup tgButton1 = DLGCreatePushButton( "Set random text", "SetText" );
    TagGroup tgButton2 = DLGCreatePushButton( "show text in result window", "ShowText" );
    Dialog.DLGAddElement( tgButton1 );
    Dialog.DLGAddElement( tgButton2 );
    Dialog.DLGAddElement( txtScript );
    alloc(handler).init(Dialog).pose();