home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / tema / MINICAD / MC7DEMO / MINICAD.1 / CHG_TBLK.MPC < prev    next >
Text File  |  1997-04-30  |  6KB  |  260 lines

  1. Procedure ChangeInfo;
  2. {
  3. ⌐1997, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie.
  5. This procedure allows the user to change any of the fields of the record named 'RecordName' that is attached to the title block symbol contained in the drawing form created by the Drawing Form command. The new values are input by the user by way of a custom dialog box. The record must contain 15 fields or less.
  6. }
  7. LABEL 5,10,20,99;
  8. CONST
  9.     RecordName='TitleBlkInfo';  {Default record name. This name can be changed by the user.}
  10. VAR
  11.     i,j,k,NFields : INTEGER;
  12.     TitleBlkH,RecordH,GroupH : HANDLE;
  13.     Field : STRING;
  14.     FieldName,FieldNameD,FieldVal,NewVal : ARRAY[1..15] OF STRING;
  15.     Abort : BOOLEAN;
  16.  
  17. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  18. VAR
  19.     scrx1,scry1,scrx2,scry2:INTEGER;
  20. BEGIN
  21.     GetScreen(scrx1,scry1,scrx2,scry2);
  22.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  23.     x2:=x1+Width; 
  24. END;
  25.  
  26. Procedure Dialog1;
  27. {
  28. This procedure creates a custom dialog box (Dialog Box #1) which asks the user for the new values of all of the fields of the record.
  29. }
  30. VAR
  31.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  32.  
  33. Procedure LocateButtons(DialogType,scnh,scnw : INTEGER);
  34. {
  35. This procedure locates the 'OK' and 'Cancel' buttons.
  36. }
  37. VAR
  38.     v1,v2,v3,v4 : INTEGER;
  39.     Mac : BOOLEAN;
  40.  
  41. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  42. VAR
  43.     Temp : INTEGER;
  44. BEGIN
  45.     Temp:=m1;
  46.     m1:=m3;
  47.     m3:=Temp;
  48.     Temp:=m2;
  49.     m2:=m4;
  50.     m4:=Temp;
  51. END;        {of Swap}
  52.  
  53. BEGIN
  54.     Mac:=FALSE;
  55.     GetVersion(v1,v2,v3,v4);
  56.     IF v4 = 1 THEN Mac:=TRUE;
  57.  
  58.     IF DialogType = 1 THEN
  59.     BEGIN
  60.         px1:=(scnw DIV 2) - 80;
  61.         px2:=(scnw DIV 2) - 10;
  62.         px3:=(scnw DIV 2) + 10;
  63.         px4:=(scnw DIV 2) + 80;
  64.         IF Mac THEN SWAP(px1,px2,px3,px4);
  65.  
  66.         py1:=scnh-40;
  67.         py2:=scnh-20;
  68.         py3:=py1;
  69.         py4:=py2;
  70.     END ELSE IF DialogType = 2 THEN
  71.     BEGIN
  72.         px1:=scnw - 180;
  73.         px2:=scnw - 110;
  74.         px3:=scnw - 90;
  75.         px4:=scnw - 20;
  76.         IF Mac THEN SWAP(px1,px2,px3,px4);
  77.  
  78.         py1:=scnh-40;
  79.         py2:=scnh-20;
  80.         py3:=py1;
  81.         py4:=py2;
  82.     END ELSE
  83.     BEGIN
  84.         px1:=scnw - 90;
  85.         px2:=scnw - 20;
  86.         px3:=px1;
  87.         px4:=px2;
  88.  
  89.         py1:=scnh -70;
  90.         py2:=scnh - 50;
  91.         py3:=scnh - 40;
  92.         py4:=scnh - 20;
  93.         IF Mac THEN SWAP(py1,py2,py3,py4);
  94.     END;
  95. END;        {of Locate Buttons}
  96.  
  97. Procedure MakeDialog1(NFields : INTEGER);
  98. CONST
  99.     y1=100;
  100.     scnw=325;
  101.     h1=30;
  102.     DialogType = 1;
  103.  
  104. VAR
  105.     scnh,j,h : INTEGER;
  106.  
  107. BEGIN
  108.     scnh:=120+25*NFields-h1;
  109.     AlignScr(scnw,x1,x2);
  110.     y2:=y1+scnh;
  111.   LocateButtons(DialogType,scnh,scnw );
  112.  
  113.     BeginDialog(1,1,x1,y1,x2,y2);
  114.         AddButton('OK',1,1,px1,py1,px2,py2);
  115.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  116.         h:=20-h1;
  117.         j:=5;
  118.         FOR i:= 1 TO NFields DO BEGIN
  119.             h:=h+25;
  120.             j:=j+2;
  121.             AddField(FieldNameD[i],j,1,20,h,125,h+15);
  122.             AddField(FieldVal[i],j+1,2,135,h,300,h+15);
  123.         END;
  124.     EndDialog;
  125. END;
  126.  
  127. BEGIN
  128.     MakeDialog1(NFields);
  129. END;
  130.  
  131. Procedure WarningDialog;
  132. {
  133. This procedure creates a warning dialog box.
  134. }
  135. VAR
  136.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2 : INTEGER;
  137.  
  138. Procedure MakeWarningDialog;
  139. CONST
  140.     y1=50;
  141.     scnh=200;scnw=400;
  142. BEGIN
  143.     AlignScr(scnw,x1,x2);
  144.     y2:=y1+scnh;
  145.     BeginDialog(2,1,x1,y1,x2,y2);
  146.         AddButton('OK',1,1,scnw/2 -35,scnh-40,scnw/2 +35,scnh-20);
  147.         AddField('Cannot proceed because of one of the following reasons:',2,1,20,9,390,25);
  148.         AddField('1 - There is no title block on the drawing',3,1,40,34,390,50);
  149.      AddField('2 - The selected object is not a drawing form',4,1,40,54,390,70);
  150.      AddField('3 - There is no record attached to the title block,',5,1,40,74,390,90);
  151.      AddField('4 - The drawing form was not created with the',6,1,40,94,390,110);
  152.      AddField('      Drawing Forms macro',7,1,40,111,390,127);
  153.     EndDialog;
  154. END;
  155.  
  156. BEGIN
  157.     MakeWarningDialog;
  158. END;
  159.  
  160. Procedure GetInfo1;
  161. {
  162. This procedure displays Dialog Box #1 and retrieves the information input by the user.
  163. }
  164. VAR
  165.     Done : Boolean;
  166.     i,n,Item : Integer;
  167. BEGIN
  168.     Done:=FALSE;
  169.     Abort:=FALSE;
  170.     GetDialog(1);
  171.     SetTitle('Change Title Block Information');
  172.     SelField(8);
  173.     REPEAT
  174.         DialogEvent(Item);
  175.         IF Item=1 THEN
  176.             Done:=TRUE;
  177.         IF Item=2 THEN BEGIN
  178.             Done:=TRUE;
  179.             Abort:=TRUE;
  180.         END; 
  181.     UNTIL Done;
  182.     n:=6;
  183.     FOR i:=1 TO NFields DO BEGIN
  184.         n:=n+2;
  185.         NewVal[i]:=GetField(n);
  186.     END;
  187.     ClrDialog;
  188. END;
  189.  
  190. Procedure GetWarningDialog;
  191. {
  192. This procedure displays the warning dialog box.
  193. }
  194. VAR
  195.     Done : Boolean;
  196.     Item : Integer;
  197. BEGIN
  198.     Done:=FALSE;
  199.     WarningDialog;
  200.     GetDialog(2);
  201.     SetTitle('Warning!');
  202.     REPEAT
  203.         DialogEvent(Item);
  204.         IF Item=1 THEN
  205.             Done:=TRUE;
  206.     UNTIL Done;
  207.     ClrDialog;
  208. END;
  209.  
  210. BEGIN
  211. {
  212. Main program.
  213.  
  214.  
  215. Get the title block and record handle.
  216. }
  217.     GroupH:=FSActLayer;
  218.     IF GroupH = NIL THEN BEGIN
  219.         SysBeep;
  220.         AlrtDialog('Drawing form is not selected!');
  221.         GOTO 99;
  222.     END;
  223.     TitleBlkH:=FInGroup(GroupH);
  224.     RecordH:=GetRecord(TitleBlkH,1);
  225.     IF RecordH = NIL THEN BEGIN
  226.         SysBeep;
  227.         GetWarningDialog;
  228.         GOTO 99;
  229.     END;
  230. {
  231. Assign the field names to the variable FieldName[i]. Append a colon to the field names to display in the dialog box.
  232. }
  233.     NFields:=NumFields(RecordH);
  234.     FOR i:=1 TO NFields DO BEGIN
  235.         FieldName[i]:=GetFldName(RecordH,i);
  236.         FieldNameD[i]:=Concat(FieldName[i],':');
  237.     END;
  238. {
  239. Get the current value of all fields of the record.
  240. }
  241.     FOR i:=1 TO NFields DO BEGIN
  242.         Field:=Concat('''',RecordName,'''','.','''',FieldName[i],'''');
  243.         FieldVal[i]:=EvalStr(TitleBlkH,Field);
  244.     END;
  245. {
  246. Display Dialog Box #1 and get the new values for the fields.
  247. }
  248.     Dialog1;
  249.     SetCursor(ArrowC);
  250.     GetInfo1;
  251.     IF Abort THEN GOTO 99;
  252. {
  253. Change the fields to the new values.
  254. }
  255.     FOR i:=1 TO NFields DO
  256.         SetRField(TitleBlkH,RecordName,FieldName[i],NewVal[i]);
  257.     Redraw;
  258. 99:END;
  259.  
  260. Run(ChangeInfo);