Jump to content
Developer Wiki and Function Reference Links ×

New dialog looping sequence


Recommended Posts

Why does the following loop through No.4 (case 01) before OK is selected?

After No.1 I would have expected No.2 to be 0, not 12255.

However, even though No.2 is 12255 (which is not a case item) it still runs case 01 (No.4) and then No.3 (still 12255) before the dialog appears in the top left of my screen (why there??).

If I choose OK then No.2, No.4, No.3 is correct as I would expect but why does it then go No.2 12256, No.3 12256.

Where am I going wrong?

procedure Main;


TBdialog1 : longint;

OK : boolean;

GridTyp, OldTyp : string;

procedure CreateTBdialog1;


AlrtDialog ('1. ');

TBdialog1 := CreateLayout ('Data', False, 'OK', 'Cancel');

CreateStaticText (TBdialog1, 4, 'Data Type:', 20);

CreateCheckBox (TBdialog1, 5, ' A');

CreateStaticText (TBdialog1, 7, 'Reference:', 20);

CreateEditText (TBdialog1, 8, OldTyp, 20);

SetFirstLayoutItem (TBdialog1, 4); SetRightItem (TBdialog1, 4, 5, 0, 0);

SetBelowItem (TBdialog1, 4, 7, 0, 1); SetRightItem (TBdialog1, 7, 8, 0, 0);


procedure GetTBdialog1Results (var Item : longint; Data : longint);

procedure GetTBdialog1Events;


GetBooleanItem (TBdialog1, 5, OK);

GetItemText (TBdialog1, 8, GridTyp); UprString (GridTyp);

AlrtDialog (Concat ('4. ', GridTyp));



AlrtDialog (Concat ('2. ', Num2StrF(Item)));

Case Item of SetupDialogC: GetTBdialog1Events;

01 : GetTBdialog1Events;

02 : ; { Cancel }

end; { case }

AlrtDialog (Concat ('3. ', Num2StrF(Item)));



OldTyp := 'AA';


If (RunLayoutDialog (TBdialog1, GetTBdialog1Results) = 1 { OK }) then begin end;


run (Main);

Link to comment

Case Item of SetupDialogC: GetTBdialog1Events;
01 : GetTBdialog1Events;

Here you state then on the 12255 event and on 1, you execute the GetTBdialog1Events procedure, so this means that on init/setup (12255), you will run it, and on 1. That's why you see it happen twice.

The setup isn't there for getting values, but for further setup of your controls. Some controls require you to set the values there instead of while building the dialog, other functions only work here etc....

PS: Can you please use the code tags? It's easier to read.

Edited by Dieter @ DWorks
Link to comment

Thanks Dieter, you are correct. I shall use code tags next time.

So how do I stop this repetition?

Can you re-sequence my code as you would suggest is the best format so I don't make the mistake again please.

What information are you privileged too :-) that allows you to know that 12255 is an init/setup? Where does the average person find this help?

Link to comment

What information are you privileged too :-) that allows you to know that 12255 is an init/setup? Where does the average person find this help?

VS is derived from the Vectorworks SDK for programming in C++. If you download the SDK and search for "minicad" in the file names, those files hold ALL the constants vectorworks uses, for instances for events of dialogs, plug-ins etc etc

Link to comment

What information are you privileged too :-) that allows you to know that 12255 is an init/setup? Where does the average person find this help?

I find a lot on http://developer.vectorworks.net, and many things I also had to find out by trying/debugging, and from others that helped me.

Also one of the reasons I started DLibrary, so people who are just starting out creating plugins can get into it more easily.

Link to comment

Can you re-sequence my code as you would suggest is the best format so I don't make the mistake again please.

Here is the code like I would have created it in VS:

Your probably want to copy paste this in you ide, as these code boxes can't get wide enough. (Notepad++ is great for vs scripts, as you can set the language to Pascal to get colors and have your code much more readable.

{// Use all-upper for reserved words, so your code is more readable.}

{// Use constants for id's and predefined stuff, so you can change them later more easily.}
{// Plus your code will be more readable, as a text says more than a number.}
isDataTypeLabel = 4;
isDataTypeField = 5;
dataTypeLabel   = 7;
dataTypeField   = 8;
labelWidth      = 20;
fieldWidth      = 20;

{// Begin your vars with a lowercase character, so you can see in code that it's a VAR and not a FUNCTION/PROCEDURE.}
dialogId    : LONGINT;
dialogResult: LONGINT;

isDataType: BOOLEAN;
gridType  : STRING;
oldType   : STRING;

PROCEDURE CreateControlsOnDialog;
	AlrtDialog('Dialog creation is being run...');

	CreateStaticText(dialogId, isDataTypeLabel, 'Data Type: ', labelWidth);
	CreateCheckBox(dialogId, isDataTypeField, ' A');
	CreateStaticText(dialogId, dataTypeLabel, 'Reference: ', labelWidth);
	CreateEditText(dialogId, dataTypeField, oldType, fieldWidth);

	SetFirstLayoutItem(dialogId, isDataTypeLabel);
	SetRightItem(dialogId, isDataTypeLabel, isDataTypeField, 0, 0);
	SetBelowItem(dialogId, isDataTypeLabel, dataTypeLabel, 0, 1); 
	SetRightItem(dialogId, dataTypeLabel, dataTypeField, 0, 0);

PROCEDURE DialogEvents(VAR item, data : LONGINT);

		{// Here you setup your controls, like doing all setters so that the data really is in there.}
		{// Be aware that some controls, even though you can define the default value on creation,}
		{// will not actually has this value when you do the getter, so therefore you have to use setter here.}
		{// Also populating dropdowns etc.. happens here.}

		{// Ok event will happen before the dialog closes, so here you can get all values from the controls}
		{// and put it into your variables, so you can use it after the dialog has been closed.}
		GetBooleanitem(dialogId, isDataTypeField, isDataType);
		GetitemText(dialogId, dataTypeField, gridType);
		AlrtDialog(Concat('Ok event has been done, we got gridType: ', gridType));

PROCEDURE CancelEvent;
		{// Cancel event also will happen before the dialog closes. You can do stuff here if you want,}
		{// but most of the time you won't need this, unless you want to reset some variables.}

	AlrtDialog(Concat('A dialog event is started for item: ', Num2StrF(item)));
	{// Each control will throw an event with it's id for the item, so if you want to react to a change}
	{// of one of your controls, you can do that. In this case the data can hold extra info on what}
	{// exactly has happened to the control, like deletion of an item in a list box etc...}
	CASE item OF
		SetupDialogC: SetupEvent;
		01: OkEvent;
		02: CancelEvent;
	AlrtDialog(Concat('The end of dialog event for item: ', Num2StrF(item)));

{// Setting the initial values of our parameters. You should do this in another procedure}
{// But we only have one now, so I'll leave it here.}
oldType := 'AA';

{// The following will create a dialog canvas we can use to put our dialog controls on.}
dialogId := CreateLayout('Data', FALSE, 'isDataType', 'Cancel');

{// We then can populate the dialog with controls.}

{// Then if the dialog layout is ok for VW, we run the dialog and get back how it was closed.}
IF (VerifyLayout(dialogId)) THEN BEGIN
	dialogResult := RunLayoutDialog(dialogId, DialogEvents);

	{// You can now act based on the result of the dialog (ok or cancel was clicked).}	

run (Main);

Keep in mind that each one has his own personal style, but there are some 'rules' most of us use to have code more readable. VS hasn't any code styling rules, but other programming languages have, like Python, and they really help structuring code and make it readable.

Edited by Dieter @ DWorks
Link to comment

Thanks Dieter, you've been a great help.

With the code above I suddenly realised that

Case Item of SetupDialogC: GetTBdialog1Events;

should really be

Case Item of SetupDialogC: SetupEvent;

which stops all the loops I was originally perplexed about.

Thanks again and have a great holiday period.

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.

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...