Jump to content
Developer Wiki and Function Reference Links ×

Dialog


Recommended Posts

OK. Time to build up the Dialogs section on vcor. Raymond, come along?

At the moment I put just one dialog there for List Browsers, but I wouldn't start learning the topic from that one.

You also might wish to subscribe the v-list. It is more advanced that this present list.

http://lists.nemetschek.net/archives/vectorscript-l.html

Mind: every question almost always has been answered before. You will find a lot of answers there.

Please check vcor's category Examples - Dialogs in a couple of days. We'll fill it up with something you can use as starter. Do nevertheless read well the VectorWorks Language Guide, available from the VW help system. It does teach you the topic enough for reading and loading values in simple dialogs.

vsd

Link to comment

Hi vsd,

Ask and you shall receive. This is a "simple" do-nothing dialog that accepts 3 numbers and displays them in a MESSAGE when finished. There is a little error detection employed and all the i's are dotted and the t's crossed.

See the next post for a truly minimal approach at doing the very least. I don't recommend living this way, but it does show what makes things tick.

Raymond

PROCEDURE Sample3itemDialog;
{ 23 February 2007 - ?2007 Raymond Mullin. All rights reserved. }
{ Create a Modern Dialog with 3 text fields and a little error checking. }
VAR
dlogID, dlogResult :Longint;
X, Y, Q :Real;					{ These variables will hold the answers after the dialog closes. }


function DefineDialog(DName :String) :Longint;
{ Define the structure of the dialog and return an ID to reference it. This does not draw the dialog on the screen. }
{ there are 4 sections for defining a Modern Dialog - Create items, Place items, Align items, & Define Help for items. }

Var
	dlogID :Longint;
Begin
	{ *** Section 1 - Create items *** }
	dlogID := CreateLayout(DName, True, 'OK', 'Cancel');	{ create dialog window and ID }

	{ define the labels for the TextEdit fields }
	CreateStaticText(dlogID, 11, 'X:', 2);	{ Creates first item, but does not place it in dialog }
	CreateStaticText(dlogID, 12, 'Y:', 2);	{ Creates second item ... }
	CreateStaticText(dlogID, 13, 'Q:', 2);	{ Creates third item ... }

	{ define the TextEdit fields }
	CreateEditText(dlogID, 21, '', 16);		{ X }
	CreateEditText(dlogID, 22, '', 16);		{ Y }
	CreateEditText(dlogID, 23, '', 16);		{ Q }


	{ *** Section 2 - Place items *** }
	{ Label for TextEdit fields }
	{ First item - always goes in upper left corner. }
	SetFirstLayoutItem(dlogID, 11);		{ X: }
	SetBelowItem(dlogID, 11, 12, 0, 0);	{ Y: }
	SetBelowItem(dlogID, 12, 13, 0, 0);	{ Q: }

	{ Text Edit Fields }
	SetRightItem(dlogID, 11, 21, 0, 0);		{ X - place to right of X: label. }
	SetRightItem(dlogID, 12, 22, 0, 0);		{ Y - place to right of Y: label. }
	SetRightItem(dlogID, 13, 23, 0, 0);		{ Q - place to right of Q: label. }


	{ *** Section 3 - Align items *** }
	AlignItemEdge(dlogID, 21, 3, 1, 0);		{ X }
	AlignItemEdge(dlogID, 22, 3, 1, 0);		{ Y }
	AlignItemEdge(dlogID, 23, 3, 1, 0);		{ Q }


	{ *** Section 4 - Define Help strings *** }
	{ Help strings are not needed - but don't leave home without them. Meaning - always include them. }
	SetHelpString(0, 'This will display when the cursor is in the dialog window, but not over any dialog item.');		{ undocumented, but nice to know }

	SetHelpString(1, 'Click this button to ACCEPT dialog settings.');						{ help string for OK button }
	SetHelpString(2, 'Click the button, or press ESC key, to CANCEL dialog and do nothing.');		{ help string for CANCEL button }

	SetHelpString(21, 'Help for your first item - X.');		{ item specific help strings. Must be less than 256 characters. }
	SetHelpString(22, 'Help for your second item - Y.');
	SetHelpString(23, 'Ignore the noise.');

	DefineDialog := dlogID;			{ return the ID when you exit this routine. }
End;		{ DefineDialog }



procedure DialogDriver(var item: Longint; data :Longint);
{ This routine is called by the Modern Dialog each time your dialog receives an event - type a character, delete or paste text, }
{ click on or tab into a new field, click on a control. The dialog manager quits when you exit this procedure and ITEM equals 1 or 2. }
{ When this routine exits any other value for ITEM, the dialog manager waits for another event. }
Begin
	case item of
		SetupDialogC: begin
				{ Do all setup here. Initialize variables, set controls, etc.}
				{ This item runs ONCE before you get control of the dialog. }

				SetField(21, Num2StrF(3));		{ set initial field value to 3 - fields are always text, even numeric ones. }
				SetField(22, Num2StrF(2));		{ set initial field value to 2.2 - fields are always text, even numeric ones. }
				SetField(23, 'must be a #');		{ set initial field value to Q - fields are always text, even numeric ones. }

			end;
		1: begin		{ OK was pressed, collect all data from dialog and get ready to exit. }
				if ValidNumStr(GetField(21), X) then			{ This line moves first value to X }
					if ValidNumStr(GetField(22), Y) then		{ This line moves second value to Y }
						if ValidNumStr(GetField(23), Q) then	{ This line moves third value to Q }
							begin
								{ *** do something here, if needed. *** }
							end
						else item := 23	{ change item if Q data was wrong. }
					else item := 22		{ change item if Y data was wrong. }
				else item := 21;			{ change item if X data was wrong. }

				if (Item<>1) then SelField(Item);			{ Return cursor to offending field. }
				if (Item=23) then SetField(23, 'must be a #');	{ reset value to Q. }
			end;
		2: begin end;					{ Cancel button }
		21, 22: begin					{ First and second field }
			{ Not necessary to do anything here, but you can if you want to. }
			{ This item will execute each time you enter this field, or type or delete a character in this field. }
			end;
		23: SYSBEEP;					{ Third field - BEEP -  Just for grins }
	end;		{ case }
End;		{ DialogDriver }



BEGIN
dlogID := DefineDialog('Dialog Name');
if VerifyLayout(dlogID) then 
	dlogResult := RunLayoutDialog(dlogID, DialogDriver);

if (dlogResult = 1) then			{ 1 means OK button was pressed. }
	message('X = ', X, '   Y = ', Y, '    Q = ', Q);		{ display values in the MESSAGE window when program completes. }
END;		{ Sample3itemDialog }
Run (Sample3itemDialog);

Link to comment

Here's the same Modern Dialog example as the one posted above with EVERY-UNNECESSARY-THING stripped out, except the comments. Gotta have comments.

HTH,

Raymond

PROCEDURE Minimal3itemDialog;
{ 23 February 2007 - ?2007 Raymond Mullin. All rights reserved. }
{ Create a skeletal Modern Dialog with 3 text fields and nothing else. This is bare bones, no frills code. }
VAR
dlogID, dlogResult :Longint;
X, Y, Q :Real;			{ These variables will hold the answers after the dialog closes. }


procedure DialogDriver(var item: Longint; data :Longint);
{ This routine is called by the Modern Dialog each time your dialog receives an event - type a character, delete or paste text, }
{ click on or tab into a new field, click on a control. The dialog manager quits when you exit this procedure and ITEM equals 1. }
{ When this routine exits any other value for ITEM, the dialog manager waits for another event. }
Begin
	case item of
		1: begin		{ OK was pressed, collect all data from dialog and get ready to exit. }
			X := Str2Num(GetField(21));		{ Move first value to X }
			Y := Str2Num(GetField(22));		{ Move second value to Y }
			Q := Str2Num(GetField(23));		{ Move third value to Q }
		end;
		23: SYSBEEP;					{ Third field - BEEP -  Just for grins }
	end;		{ case }
End;		{ DialogDriver }


BEGIN
{ *** Section 1 - Create items *** }
dlogID := CreateLayout('No Frills Dialog', False, 'OK', '');		{ create dialog window and ID }

{ define 3 TextEdit fields }
CreateEditText(dlogID, 21, '', 16);			{ X }
CreateEditText(dlogID, 22, '', 16);			{ Y }
CreateEditText(dlogID, 23, '', 16);			{ Q }

{ *** Section 2 - Place items *** }
SetFirstLayoutItem(dlogID, 21);			{ First item - always goes in upper left corner }
SetBelowItem(dlogID, 21, 22, 0, 0);		{ Y - place below X field. }
SetBelowItem(dlogID, 22, 23, 0, 0);		{ Q - place below Y field. }

{ *** Run the dialog *** }
dlogResult := RunLayoutDialog(dlogID, DialogDriver);

{ *** Harvest the results *** }
if (dlogResult = 1) then			{ 1 means OK button was pressed. }
	message('X = ', X, '   Y = ', Y, '    Q = ', Q);		{ display values in the MESSAGE window when program completes. }
END;		{ Minimal3itemDialog }
Run (Minimal3itemDialog);

Link to comment

someonenamed... you are a lucky person. Raymond gave you a really sweet bit to chew upon!

Raymond, you allow me to wikify?

Cancel or allow?

I would only put the dialog items' IDs on a CONST block at the beginning. I think it is a good habit to start upon. This way it is easier to maintain them later, when your dialog grows (it will, it always does)

Someonenamed a link (how did you come up with such a name? is worst than all my identities together), I think the time is ripe for "Spiteful PIO".

Some of us would call it "Tamagotschi" plugin, but I am afraid I won't be allowed to name it so on vcor, name traded, or I should ban myself there. Which I think would be a pity.

Raymond, come on, let's do it on the weekend. It is the perfect object for demonstration purposes! Or do you have some other plan than laugh your head off for two days on a row? grin.gif

Orso

Edited by _c_
Link to comment

No! I had to google that!

I stopped doing videogames by Lara Croft (how was that called?). I realized I had to choose between a life and that. (the question is: if scripting or being an architect, and, worst, both together, is a life).

Please forgive me, I've been truly rude.

Orso

Link to comment

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.

×
×
  • Create New...