Jump to content
michaelk

Dialog boxes :-{

Recommended Posts

I'm trying to use some of this enforced down time to learn the dark art of dialog boxes.

 

I've been looking at examples and reading the developer pages.  I'm getting closer.  I'm hoping someone can point out my misunderstandings.

 

Do I need different variables in the function that runs the dialog box than in the main script?  What am I doing wrong here?

 

Thanks!

Procedure DialogsAreConfusing; 

var
	StackingBegin,StackingEnd,RenumBegin: integer;
	Prefix,Suffix:STRING;

FUNCTION Mydialog(var StackingBegin,StackingEnd,RenumBegin :integer; var Prefix,Suffix :STRING) :boolean;

VAR

	id :INTEGER;
	result  :INTEGER;


	PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);
		VAR  
		dhPrefix,dhSuffix							: STRING;
		dhStackingBegin,dhStackingEnd,dhRenumBegin	: INTEGER;

		BEGIN
		CASE item OF
			SetupDialogC:
				BEGIN
					SetEditInteger(id,6,1);
					SetEditInteger(id,7,2);
					SetItemText(id,12,'A');
					SetEditInteger(id,13,2);
					SetItemText(id,14,'');
				END;
			1:
				BEGIN
					
					GetEditInteger(id,6,dhStackingBegin);
					GetEditInteger(id,7,dhStackingEnd);
					
					GetItemText(id,12,dhPrefix);
					GetEditInteger(id,13,dhRenumBegin);
					GetItemText(id,14,dhSuffix);
					
				END;
			2:
				BEGIN
				END;
		END; {Case}
	END; {Dialog Handler}

BEGIN
	id:=CreateLayout('Dialog Boxes Are Confusing',TRUE,'OK','Cancel');
	
	CreateStaticText(id,4,'First',-1);
	CreateStaticText(id,5,'Last',-1);
	CreateEditInteger(id,6,1,6);
	CreateEditInteger(id,7,1,6);
	CreateStaticText(id,9,'Prefix',-1);
	CreateStaticText(id,10,'Num',-1);
	CreateStaticText(id,11,'Suffix',-1);
	CreateEditText(id,12,'A',6);
	CreateEditInteger(id,13,0,6);
	CreateEditText(id,14,'',6);
	
	SetFirstLayoutItem(id,4);
	SetRightItem(id,4,6,0,0);
	SetBelowItem(id,4,5,0,0);
	SetRightItem(id,5,7,0,0);
	SetBelowItem(id,5,9,0,0);
	SetRightItem(id,9,10,1,0);
	SetRightITem(id,10,11,2,0);
	SetBelowItem(id,9,12,0,0);
	
	SetBelowItem(id,10,13,0,0);
	SetBelowItem(id,11,14,0,0);
	

	
	
	
	result := RunLayoutDialog(id, Dialog_Handler);

	IF result = 2 	THEN Mydialog := FALSE 
					ELSE Mydialog := TRUE;
END; {Mydialog}

BEGIN {main} 

	IF Mydialog(StackingBegin,StackingEnd,RenumBegin,Prefix,Suffix) THEN
		BEGIN

		MESSAGE	('Stacking Begin: ',StackingBegin,CHR(13);
				'Stacking End: ',StackingEnd,CHR(13);
				'Prefix: ',Prefix,CHR(13);
				'RenumBegin: ',RenumBegin,CHR(13);
				'Suffix: ',Suffix);

   END;
END; {main} 

run(DialogsAreConfusing);

 

Share this post


Link to post

You basically have some scope issues, as you never transfer the values of all your dh* variables to your global variables. 
 

The way you have the code structured now, either define your dh variables as the MyDialog function parameters, or add to your ok event transferring handler variables to function variables, e.g. stackingBegin := dhStackingBegin. 
 

Sometimes having a separate set of variables for the handler makes sense, for example of fields adjust based on data in other parts of the dialog, but in your case you can just use one set of variables all the way through. 
 

Also, I highly recommend using constants to identify control ID’s. 

Share this post


Link to post

Thanks Josh.

 

So it's not necessary (in a simple script) to have separate variables?  That's what I was confused about.  

 

What do you mean about using constants to control IDs?  

 

 

Share this post


Link to post

There’s nothing special about the scope of the dialog handler — just think of it as a procedure that runs every time the user interacts with the dialog. Variables declared as part of the handler will only keep values for each run of the handler procedure. If you need to get or set values outside the handler, use values outside the handler’s scope. 
 

 

To use constants for control ID’s, declare a constant for each ID, including ok and cancel at a scope where both the creation and handler code can access them:

 

kOk = 1;

kCancel = 2;

kStaticFirst = 4;

etc.

 

That way you don’t have to remember what ID number you used with each create command, and you don’t have to renumber when adding in new controls   

Share this post


Link to post

Thanks, Josh.  

 

Finally got it.  And what you say about constants makes a lot of sense.

 

Pat and Sam were nice enough to set me straight in a zoom meeting.  I now feel like I basically understand dialogs, but I don't think that reading the documentation would have ever gotten me there!

 

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...