Dlog-Generic Pulldown dialog by dynarray

From Vectorlab
Jump to: navigation, search


Generic dialog with a pulldown menu built from a dynarray of string. If user confirms the dialog with "OK" the routine returns true and sets the passed variables to the chosen index and string in the dynarray. Otherwise, if the user canceled, the routine returns false. There are basic examples of its usage at Generic Pulldown dialog (array of string) and Generic Record Dialog. By Orso B. Schmid


{  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;
		
	
	{ Orso B. Schmid ************************************************ }
	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;