Generic Pulldown dialog (array of string)

From Vectorlab
Jump to: navigation, search


A generic dialog with a pulldown menu from an array of string. In this example we load the pulldown menu with a list of characters, but you could use anything you wish. By Orso B. Schmid

NOTE
based upon the subroutine Dlog-Generic Pulldown dialog by dynarray


{ 
************************************************
Orso. B. Schmid
************************************************
}

PROCEDURE xxxxx;
	VAR
		arr : ARRAY[1..26] OF STRING;
		i, num : INTEGER;
		str : STRING;
		
		
	{ ************************************************ }
	{ returns a resource string at given index and number }
	FUNCTION D_GetStr(resID, resNr: INTEGER): STRING;
		VAR
			str : STRING;
		BEGIN
			GetResourceString(D_GetStr, resID, resNr);
		END;
			
	{ Orso B. Schmid ************************************************ }
	{ outputs a generic dialog with a pull down menu from string array }
	{ sets vars with the chosen pull down index and string }
	FUNCTION D_GenericPullDialog(title, staticTxt: STRING; pullChoices: DYNARRAY[] OF STRING; VAR choiceNum: INTEGER; VAR choiceStr: STRING): BOOLEAN;
		VAR
			choiceCnt : INTEGER;
			temp_i : INTEGER;
			
		
		{ ************************************************ }
		FUNCTION Dialog_Layout: INTEGER;
			VAR
				d, longest: INTEGER;
				i : INTEGER;
				
			BEGIN
				d := CreateLayout(title, FALSE, D_GetStr(174, 1), D_GetStr(174, 2));
				
				{ find out longest item }
				i := 1;
				longest := Len(staticTxt);
				WHILE i < choiceCnt + 1 DO BEGIN
					longest := max(longest, Len(pullChoices[i]));
					i := i + 1;
				END;
				
				IF longest > 64 THEN
					longest := 64;
				longest := longest +4;
				
				CreateStaticText(d, 10, staticTxt, longest);
				CreatePullDownMenu(d, 11, longest);
				
				SetFirstLayoutItem(d, 10);
				SetBelowItem(d, 10, 11, 0, 0);
				
				Dialog_Layout := d;
			END;
		
		PROCEDURE Dialog_Driver(VAR item:LONGINT; data:LONGINT);
			VAR
				i : INTEGER;
				
			BEGIN
				CASE item OF
				SetupDialogC: 
					BEGIN
						i := 0;
						WHILE i < choiceCnt DO BEGIN
							i := i + 1;
							InsertChoice(11, i-1, pullChoices[i]);
						END;
						
						choiceStr := pullChoices[1];
					END;
					
				{ user hit OK }
				1:	GetSelChoice(11, 0, choiceNum, choiceStr);
				
				{ user hit Cancel }
				2: 	BEGIN
						choiceNum := -1;
						choiceStr := '';
					END;
				
				END;
			END;
		
		BEGIN
			GetArrayDimensions(pullChoices, temp_i, choiceCnt, temp_i, temp_i);
			D_GenericPullDialog := (RunLayoutDialog(Dialog_Layout, Dialog_Driver) = 1);
			{ dialog confirmed OK }
		END;

BEGIN
	FOR i:= 65 TO 90 DO
		arr[i-64] := chr(i); { letters from A to Z }
		
	IF D_GenericPullDialog('My generic list dialog', 'Select a letter',  arr, num, str) THEN
		AlrtDialog(Concat('You chose: ', str));

END;

Run(xxxxx);