Generic Record Dialog

From Vectorlab
Jump to: navigation, search


A generic dialog to list records. It allows to parse for hidden records or not, according to the parameter "Advanced". This ignores plug-in records. 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;
		
	{ Orso B. Schmid ************************************************ } 
	{ choose a record, uses a dialog if more recs available }
	{ use Advanced TRUE to parse also hidden records }
	{ THIS DOESN'T PARSE PLUGINS }
	FUNCTION D_ChooseObjectRec(h: HANDLE; advanced: BOOLEAN): STRING;
		VAR
			recCnt, recNr, i: INTEGER;
			recs : DYNARRAY[] OF STRING;
			objN : STRING;
			li : LONGINT;
			
		BEGIN
			{ parse only visible recs }
			{ I don't use res lists because they fail on single ojbjects }
			IF NOT advanced THEN BEGIN
				recCnt := NumRecords(h);
				
				IF recCnt = 1 THEN BEGIN
					D_ChooseObjectRec := GetName(GetRecord(h, 1));
					
				END ELSE IF recCnt > 1 THEN BEGIN
					ALLOCATE recs[1..recCnt];
					
					i := 0;
					WHILE i < recCnt DO BEGIN
						i := i + 1; 
						recs[i] := GetName(GetRecord(h, i));
					END;
					
					IF NOT D_GenericPullDialog('Records', 'Choose a record:', recs, recNr, D_ChooseObjectRec) THEN { sets recNr }
						SysBeep;
					
				END;
		
			{ catch also hidden recs }
			END ELSE BEGIN
				recCnt := 0;
				ALLOCATE recs[1..NameNum];
				
				FOR li := 1 TO NameNum DO BEGIN
					objN := NameList(li);
					
					{ is valid name }
					IF Len(objN) > 0 THEN
						IF (GetType(GetObject(objN)) = 47) THEN BEGIN
							recCnt := recCnt+1;
							recs[recCnt] := objN;
						END;
				END;
					
				ALLOCATE recs[1..recCnt];
				SortArray(recs, recCnt, 0);
					
				IF NOT D_GenericPullDialog('Records', 'Choose a record:', recs, recNr, D_ChooseObjectRec) THEN { sets recNr }
					SysBeep;
			END;
		END;

BEGIN
	AlrtDialog(D_ChooseObjectRec(FSActLayer, TRUE));
END;

Run(xxxxx);