home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 035A / COMPED2.ZIP / E_CMPED.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-13  |  28.0 KB  |  884 lines

  1. unit E_cmpEd;
  2.  
  3. interface
  4. (*******************************************************************
  5.                             E_CmpEd
  6.     Object Inspector/Component Editor.
  7.     Author : David Spies
  8.     Contacts : Work - davidsp@eastsoft.com Home DSPIES@onecom.com  *)
  9. uses
  10.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  11.   Grids, StdCtrls, Buttons, ExtCtrls, ComCtrls, E_Props,
  12.   Consts;
  13.  
  14. type
  15.   TCompEditForm = class(TForm)
  16.     StringGrid1: TStringGrid;
  17.     StatusBar1: TStatusBar;
  18.     Panel1: TPanel;
  19.     ComponentBox: TComboBox;
  20.     EditStr: TEdit;
  21.     ComboEnum: TComboBox;
  22.     SetEdit: TListBox;
  23.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  24.     procedure Panel1Resize(Sender: TObject);
  25.     procedure ComponentBoxChange(Sender: TObject);
  26.     procedure FormResize(Sender: TObject);
  27.     procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Longint;
  28.                                     var CanSelect: Boolean);
  29.     procedure StringGrid1DblClick(Sender: TObject);
  30.     procedure FixUpOnExit(Sender: TObject);
  31.     procedure EditStrKeyPress(Sender: TObject; var Key: Char);
  32.     procedure EditkeyDown(Sender: TObject; var Key: Word;
  33.       Shift: TShiftState);
  34.     procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
  35.   private
  36.     { Private declarations }
  37.     PropList     : TStringList;
  38.     FComponent   : TComponent;
  39.     CurComponent : TComponent;
  40.     CompProp     : TEProperty;
  41.     Procedure ShowCurrentComponent;
  42.     procedure ClearStringGrid;
  43.     procedure ClearPropList;
  44.     procedure DoLastControl;
  45.     Procedure EGetStrs(Const s : String);
  46.     procedure SetEditBounds(AControl : TWinControl);
  47.     Procedure SetStatusBar(Sender : TObject;
  48.                            ARow   : Integer);
  49.     procedure EditProperty(CurCol ,
  50.                            CurRow : LongInt);
  51.     procedure ClearEdit(Sender: TObject);
  52.   public
  53.     { Public declarations }
  54.     Procedure Execute(AComponent : TComponent;
  55.                       IsModal    : Boolean);
  56.  end;
  57.  Procedure EditAComponent(AComponent : TComponent;
  58.                           ACaption   : String;
  59.                           IsModal    : Boolean);
  60. var
  61.   CompEditForm: TCompEditForm;
  62.  
  63. implementation
  64.  
  65. {$R *.DFM}
  66. Uses
  67.      Db,DbTables,FileCtrl,ImageWin,StrEdit;
  68. Type
  69.        ECompEditError   = class(Exception);
  70. Const
  71.        MrArray   : Array[mrNone..MrNo] Of String =
  72.         ('mrNone',
  73.          'mrOk',
  74.          'mrCancel',
  75.          'mrAbort',
  76.          'mrRetry',
  77.          'mrIgnore',
  78.          'mrYes',
  79.          'mrNo');
  80. Function StripAllChr(InStr    : String;
  81.                      StripChr : Char) : String;
  82. Var
  83.   I : Integer;
  84. begin
  85.   I := 1;
  86.   while (I <= Length(InStr)) do
  87.     if InStr[I] = StripChr then
  88.       Delete(InStr, I, 1)
  89.     else
  90.       Inc(I);
  91.   Result := InStr;
  92. end;
  93. Procedure GetFileList(FPath : String;
  94.                       Mask  : String;
  95.                       FList : TStrings);
  96. Var
  97.     TMask     : String;
  98.     P         : Integer;
  99.     FResult   : Integer;
  100.     SearchRec : TSearchrec;
  101. begin
  102.   FList.Clear;
  103.   If FPath='' then
  104.     Exit;
  105.   If NOT DirectoryExists(FPath) then
  106.     Exit;
  107.   If FPath[Length(FPath)]<>'\' then
  108.     Fpath:=FPath+'\';
  109.   While Mask<>'' do
  110.   begin
  111.     P:=Pos(';',Mask);
  112.     If P=0 then
  113.       P:=Succ(Length(Mask));
  114.     TMask:=Copy(Mask,1,Pred(P));
  115.     Delete(Mask,1,P);
  116.     FResult := SysUtils.FindFirst(FPath+TMask,0,SearchRec);
  117.     while FResult = 0 do
  118.     begin
  119.       FList.Add(SearchRec.Name);
  120.       FResult := SysUtils.FindNext(SearchRec);
  121.     end;
  122.     SysUtils.FindClose(SearchRec);
  123.   end;
  124. end;
  125. Procedure EditAComponent(AComponent : TComponent;
  126.                          ACaption   : String;
  127.                          IsModal    : Boolean);
  128. Var
  129.     AForm : TCompEditForm;
  130. begin
  131.   AForm:=TCompEditForm.Create(Application);
  132.   If ACaption<>'' then
  133.     AForm.Caption:=ACaption;
  134.   AForm.Execute(AComponent,True);
  135.   AForm.Free;
  136. end;
  137. procedure TCompEditForm.FormClose(    Sender: TObject;
  138.                                   var Action: TCloseAction);
  139. begin
  140.   ClearPropList; {Clear the property list and free the form}
  141. end;
  142. procedure TCompEditForm.ClearStringGrid;
  143. Var
  144.     I       : Integer;
  145. begin
  146.   For I:=0 To StringGrid1.RowCount-1 do
  147.   begin
  148.     StringGrid1.Cells[0,I]:='';
  149.     StringGrid1.Cells[1,I]:='';
  150.   end;
  151. end;
  152. procedure TCompEditForm.ClearPropList;
  153. Var
  154.     I       : Integer;
  155. begin                   {Clear the Property List}
  156.   If PropList<>Nil then
  157.     For I:=0 to PropList.Count-1 do
  158.     begin
  159.       CompProp:=PropList.Objects[I] As TEProperty;
  160.       CompProp.Free;
  161.     end;
  162.   PropList.Free;
  163.   PropList:=Nil;
  164.   CompProp:=Nil;
  165.   ClearStringGrid;
  166. end;
  167. procedure TCompEditForm.Panel1Resize(Sender: TObject);
  168. begin
  169.   ComponentBox.Width:=Panel1.Width;
  170. end;
  171. Procedure TCompEditForm.ShowCurrentComponent;
  172. Var
  173.     S          : String;
  174.     ACount     : Integer;
  175.     I          : Integer;
  176.     AComponent : TComponent;
  177.     TInt       : Integer;
  178.                Procedure DelCurrent;
  179.                begin
  180.                  CompProp:=PropList.Objects[I] As TEProperty;
  181.                  CompProp.Free;
  182.                  PropList.Delete(I);
  183.                  Dec(Acount);
  184.                end;
  185. begin
  186.   S :=Copy(ComponentBox.Text,1,Pred(Pos(':',ComponentBox.Text)));
  187.   AComponent:=FComponent;
  188.   If S<>'' then
  189.     For I:=0 to FComponent.ComponentCount-1 do
  190.       If FComponent.Components[I].Name=S then
  191.       begin
  192.         AComponent:=FComponent.Components[I];
  193.         Break;
  194.       end;
  195.   If (AComponent<>Nil) AND (AComponent<>CurComponent) then
  196.   begin
  197.     CurComponent:=AComponent;
  198.     ClearPropList;
  199.     ACount:=E_EnumProperties(CurComponent,PropList);
  200.     I:=0;
  201.     While I<ACount do
  202.     begin
  203.       S:=UpperCase(PropList.Strings[I]);
  204.       If (S='MASTERFIELDS') OR (S='MASTERSOURCE') OR
  205.          (S='SESSIONNAME') OR (S='UPDATEOBJECT') OR
  206.          (S='INDEXFILES') then
  207.         DelCurrent
  208.       else
  209.         Inc(I);
  210.     end;
  211.     If ACount>0 then
  212.     begin
  213.       StringGrid1.RowCount:=ACount;
  214.       For I:=0 to ACount-1 do
  215.       begin
  216.         StringGrid1.Cells[0,I]:=PropList.Strings[I];
  217.         CompProp:=PropList.Objects[I] As TEProperty;
  218.         If UpperCase(PropList.Strings[I])='MODALRESULT' then
  219.         begin
  220.           TInt:=StrToInt(CompProp.PValue);
  221.           If (TInt<MrNone) OR (TInt>MrNo) then
  222.             TInt:=mrNone;
  223.           CompProp.PValue:=mrArray[TInt];
  224.           CompProp.EType:=PROP_MODALTYPE;
  225.         end;
  226.         StringGrid1.Cells[1,I]:=CompProp.PValue;
  227.       end;
  228.       StringGrid1.Col:=1;
  229.       StringGrid1.Row:=0;
  230.     end
  231.     else
  232.       StringGrid1.RowCount:=0;
  233.   end;
  234. end;
  235. procedure TCompEditForm.ComponentBoxChange(Sender: TObject);
  236. begin
  237.   ShowCurrentComponent;
  238. end;
  239. Procedure TCompEditForm.Execute(AComponent : TComponent;
  240.                                 IsModal    : Boolean);
  241. Var
  242.      I : Integer;
  243.               Function AddComponent(AComponent : TComponent) : String;
  244.               begin
  245.                 Result:=AComponent.Name+':'+AComponent.ClassName;
  246.               end;
  247. begin
  248.   ComponentBox.Items.Clear;
  249.   FComponent:=AComponent;
  250.   If FComponent.ComponentCount>1 then
  251.     ComponentBox.Items.Add(AddComponent(FComponent))
  252.   else
  253.     ComponentBox.Enabled:=False;
  254.   For I:=0 to FComponent.ComponentCount-1 do
  255.     ComponentBox.Items.Add(AddComponent(FComponent.Components[I]));
  256.   ComponentBox.ItemIndex:=0;
  257.   CurComponent:=Nil;
  258.   ShowCurrentComponent;
  259.   If IsModal then
  260.   begin
  261.     BorderIcons:=BorderIcons-[biMinimize];
  262.     Height:=Height DIV 2;
  263.     ShowModal;
  264.   end
  265.   else
  266.     Show;
  267. end;
  268.  
  269. procedure TCompEditForm.FormResize(Sender: TObject);
  270. begin
  271.   StringGrid1.DefaultColWidth:=(ClientWidth-20) DIV 2;
  272.   With StringGrid1 do
  273.   begin
  274.     ColWidths[0]:=DefaultColWidth;
  275.     ColWidths[1]:=DefaultColWidth;
  276.   end;
  277.   If (ActiveControl=EditStr) OR (ActiveControl=ComboEnum) OR
  278.      (ActiveControl=SetEdit) then
  279.     SetEditBounds(ActiveControl);
  280. end;
  281. procedure TCompEditForm.DoLastControl;
  282. Var
  283.     CurRow  : Integer;
  284.     PropStr : String;
  285.     S       : String;
  286.     TInt    : Integer;
  287.     Tf      : Extended;
  288.     TBool   : Boolean;
  289.     CAddr   : LongInt;
  290.     I,J     : Integer;
  291. begin
  292.   CurRow:=StringGrid1.Row;
  293.   If CurRow<Proplist.Count then
  294.   begin
  295.     PropStr:=PropList.Strings[CurRow];
  296.     CompProp:=PropList.Objects[CurRow] AS TEProperty;
  297.     If CompProp<>Nil then
  298.     begin
  299.       If CompProp.EType=PROP_STRTYPE then
  300.       begin
  301.         If E_SetStrProp(CurComponent,PropStr,EditStr.Text) then
  302.           CompProp.PValue:=EditStr.Text;
  303.       end
  304.       else If CompProp.EType=PROP_CHARTYPE then
  305.       begin
  306.         S:=StripAllChr(EditStr.Text,#32);
  307.         If S='' then
  308.           TInt:=0
  309.         else If S[1]='#' then
  310.         begin
  311.           Delete(S,1,1);
  312.           TInt:=StrToInt(S);
  313.         end
  314.         else
  315.           TInt:=Ord(S[1]);
  316.         If E_SetIntProp(CurComponent,PropStr,TInt) then
  317.           CompProp.PValue:=EditStr.Text;
  318.       end
  319.       else If CompProp.EType=PROP_BOOLTYPE then
  320.       begin
  321.         If E_SetBoolProp(CurComponent,PropStr,ComboEnum.Text='True') then
  322.           CompProp.PValue:=ComboEnum.Text;
  323.       end
  324.       else If CompProp.EType=PROP_INTTYPE then
  325.       begin
  326.         TInt:=StrToInt(EditStr.Text);
  327.         With CompProp do
  328.           if (TInt < MinVal) or (TInt > MaxVal) then
  329.             raise ECompEditError.CreateResFmt(SOutOfRange, [MinVal,MaxVal]);
  330.         If E_SetIntProp(CurComponent,PropStr,TInt) then
  331.           CompProp.PValue:=EditStr.Text;
  332.       end
  333.       else If CompProp.EType=PROP_REALTYPE then
  334.       begin
  335.         Tf:=StrToFloat(EditStr.Text);
  336.         If E_SetRealProp(CurComponent,PropStr,Tf) then
  337.           CompProp.PValue:=EditStr.Text;
  338.       end
  339.       else If CompProp.EType IN [PROP_ENUMTYPE,PROP_MODALTYPE] then
  340.       begin
  341.         If E_SetIntProp(CurComponent,PropStr,ComboEnum.ItemIndex) then
  342.           CompProp.PValue:=ComboEnum.Text;
  343.       end
  344.       else If CompProp.EType=PROP_SETTYPE then
  345.       begin
  346.         CompProp.PValue:='[';
  347.         For TInt:=0 to SetEdit.Items.Count-1 do
  348.           If SetEdit.Selected[TInt] then
  349.           begin
  350.             if Length(CompProp.PValue) <> 1 then
  351.               CompProp.PValue:=CompProp.PValue+',';
  352.             CompProp.PValue:=CompProp.PValue+SetEdit.Items.Strings[TInt];
  353.           end;
  354.         CompProp.PValue:=CompProp.PValue+']';
  355.         If NOT E_SetSetStrProp(CurComponent,PropStr,CompProp.PValue) then
  356.           CompProp.PValue:=StringGrid1.Cells[1,CurRow];
  357.       end
  358.       else If CompProp.EType=PROP_COLORTYPE then
  359.       begin
  360.         If E_SetIntProp(CurComponent,PropStr,StringToColor(ComboEnum.Text)) then
  361.           CompProp.PValue:=ComboEnum.Text;
  362.       end
  363.       else If CompProp.EType=PROP_CURSORTYPE then
  364.       begin
  365.         If E_SetIntProp(CurComponent,PropStr,StringToCursor(ComboEnum.Text)) then
  366.           CompProp.PValue:=ComboEnum.Text;
  367.       end
  368.       else If CompProp.EType IN [PROP_DBNAMETYPE,PROP_DBIDXNAMETYPE,
  369.                                  PROP_DBTABNAMETYPE,PROP_DBLOOKUPFIELD] then
  370.       begin
  371.         If E_SetStrProp(CurComponent,PropStr,ComboEnum.Text) then
  372.           CompProp.PValue:=ComboEnum.Text;
  373.       end
  374.       else If CompProp.EType = PROP_CLASSTYPE then
  375.       begin
  376.         If CompProp.SubType=PROP_DATASETSUB then
  377.         begin
  378.           If ComboEnum.Text='' then
  379.             CAddr:=0
  380.           else
  381.           begin
  382.             TBool:=False;
  383.             For I:=0 to FComponent.ComponentCount-1 do
  384.               If FComponent.Components[I] IS TTable then
  385.                If CompareText(ComboEnum.Text,(TTable(FComponent.Components[I]).Name))=0 then
  386.                begin
  387.                  TBool:=True;
  388.                  CAddr:=Longint(FComponent.Components[I]);
  389.                  Break;
  390.                end;
  391.             If NOT TBool then With Session do  for I:= 0 to DatabaseCount - 1 do
  392.               With Databases[I] do
  393.                 For J:=0 to DataSetCount-1 do
  394.                 If CompareText(ComboEnum.Text,DataSets[I].Name)=0 then
  395.                begin
  396.                  CAddr:=Longint(DataSets[I]);
  397.                  Break;
  398.                end;
  399.             If E_SetIntProp(CurComponent,PropList.Strings[CurRow],CAddr) then
  400.             begin
  401.               CompProp.PValue:=ComboEnum.Text;
  402.               CompProp.ClassAddr:=CAddr;
  403.             end;
  404.           end;
  405.         end
  406.         else If CompProp.SubType=PROP_DATASOURCESUB then
  407.         begin
  408.           TBool:=True;
  409.           CAddr:=0;
  410.           If ComboEnum.Text<>'' then
  411.           begin
  412.             For I:=0 to FComponent.ComponentCount-1 do
  413.               If FComponent.Components[I] IS TdataSource then
  414.                If CompareText(ComboEnum.Text,(TdataSource(FComponent.Components[I]).Name))=0 then
  415.                begin
  416.                  CAddr:=Longint(FComponent.Components[I]);
  417.                  Break;
  418.                end;
  419.             TBool:=E_SetIntProp(CurComponent,PropList.Strings[CurRow],CAddr);
  420.           end;
  421.           If TBool then
  422.           begin
  423.             CompProp.PValue:=ComboEnum.Text;
  424.             CompProp.ClassAddr:=CAddr;
  425.           end;
  426.         end;
  427.       end;
  428.       StringGrid1.Cells[1,CurRow]:=CompProp.PValue;
  429.     end;
  430.   end;
  431. end;
  432. Procedure TCompEditForm.SetStatusBar(Sender : TObject;
  433.                                      ARow   : Integer);
  434. begin
  435.   If Assigned(PropList) then
  436.     If Sender IS TStringGrid then
  437.       If TEProperty(PropList.Objects[ARow]).EType=PROP_NOTYPE then
  438.         StatusBar1.SimpleText:='This Property Cannot Be Edited'
  439.       else
  440.         StatusBar1.SimpleText:='Double Click/Enter To Edit Property'
  441.     else
  442.       StatusBar1.SimpleText:='Escape To Cancel'
  443.   else
  444.     StatusBar1.SimpleText:='';
  445. end;
  446. procedure TCompEditForm.StringGrid1SelectCell(Sender        : TObject;
  447.                                               Col           ,
  448.                                               Row           : Longint;
  449.                                               var CanSelect : Boolean);
  450. begin
  451.   If Col=1 then
  452.   begin
  453.     CanSelect:=True;
  454.     SetStatusBar(StringGrid1,Row);
  455.   end
  456.   else
  457.     CanSelect:=False;
  458. end;
  459. Procedure TCompEditForm.EGetStrs(Const s : String);
  460. begin
  461.   ComboEnum.Items.Add(S);
  462. end;
  463. procedure TCompEditForm.SetEditBounds(AControl : TWinControl);
  464. Var
  465.     Rect : TRect;
  466. begin
  467.   If AControl<>Nil then With AControl do
  468.   begin
  469.     CompProp:=PropList.Objects[StringGrid1.Row] AS TEProperty;
  470.     Rect := StringGrid1.CellRect(1,StringGrid1.Row);
  471.     If CompProp.EType = PROP_SETTYPE then
  472.     begin
  473.       Left:=0;
  474.       Top:=Rect.Top+StringGrid1.Top+StringGrid1.DefaultRowHeight;
  475.       Height:=StringGrid1.DefaultRowHeight*3;
  476.       Width:=StringGrid1.Width;
  477.     end
  478.     else
  479.     begin
  480.       Left:=Rect.Left+1;
  481.       Top:=Rect.Top+StringGrid1.Top;
  482.       Height:=StringGrid1.DefaultRowHeight;
  483.       Width:=StringGrid1.DefaultColWidth;
  484.     end;
  485.     StatusBar1.SimpleText:='';
  486.     Visible:=True;
  487.     ActiveControl:=AControl;
  488.     SetStatusBar(AControl,0);
  489.   end
  490. end;
  491. procedure TCompEditForm.EditProperty(CurCol ,
  492.                                      CurRow : LongInt);
  493. Var
  494.     DoIt       : Boolean;
  495.     CurEdit    : TWinControl;
  496.     I,J        : Integer;
  497.     S          ,
  498.     Ts         : String;
  499.     FontDialog : TFontDialog;
  500.     AList      : TStrings;
  501.     TBool      : Boolean;
  502.     CAddr      : Longint;
  503.                 Function GetDataBaseName : Boolean;
  504.                 begin
  505.                   Result:=False;
  506.                   If StringGrid1.RowCount>0 then
  507.                   begin
  508.                     I:=0;
  509.                     While (I<StringGrid1.RowCount) AND (UpperCase(StringGrid1.Cells[0,I])<>'DATABASENAME') do
  510.                       Inc(I);
  511.                     If I<StringGrid1.RowCount then
  512.                     begin
  513.                       S:=StringGrid1.Cells[1,I];
  514.                       Result:=S<>'';
  515.                     end;
  516.                   end;
  517.                 end;
  518.                 Function GetDataBasePath : Boolean;
  519.                 begin
  520.                   Result:=False;
  521.                   AList:=TStringList.Create;
  522.                   Session.GetAliasParams(S,AList);
  523.                   S:='';
  524.                   I:=0;
  525.                   While I < AList.Count do
  526.                     If Pos('PATH',UpperCase(Alist.Strings[I]))>0 then
  527.                     begin
  528.                       S:=AList.Strings[I];
  529.                       Delete(S,1,Pos('=',S));
  530.                       Result:=True;
  531.                       Break;
  532.                     end
  533.                     else
  534.                       Inc(I);
  535.                     AList.Free;
  536.                 end;
  537.                 Function GetTableName : Boolean;
  538.                 begin
  539.                   Result:=False;
  540.                   S:='';
  541.                   If StringGrid1.RowCount>0 then
  542.                   begin
  543.                     I:=0;
  544.                     While (I<StringGrid1.RowCount) AND (UpperCase(StringGrid1.Cells[0,I])<>'TABLENAME') do
  545.                       Inc(I);
  546.                     If I<StringGrid1.RowCount then
  547.                       S:=StringGrid1.Cells[1,I];
  548.                     Result:=S<>'';
  549.                   end;
  550.                 end;
  551.                 Function GetLookUpSource : Boolean;
  552.                 begin
  553.                   Result:=False;
  554.                   CAddr:=0;
  555.                   If StringGrid1.RowCount>0 then
  556.                   begin
  557.                     I:=0;
  558.                     While (I<StringGrid1.RowCount) AND (UpperCase(StringGrid1.Cells[0,I])<>'LOOKUPSOURCE') do
  559.                       Inc(I);
  560.                     If I<StringGrid1.RowCount then
  561.                     begin
  562.                       S:=StringGrid1.Cells[1,I];
  563.                       If S<>'' then
  564.                         CAddr:=LongInt(TDataSource(TeProperty(PropList.Objects[I]).ClassAddr).DataSet);
  565.                     end;
  566.                     Result:=CAddr>0;
  567.                   end;
  568.                 end;
  569. begin
  570.   If (PropList=Nil) OR (CurCol<>1) then
  571.     Exit;
  572.   CompProp:=PropList.Objects[CurRow] AS TEProperty;
  573.   If CompProp.EType IN [PROP_STRTYPE,PROP_INTTYPE,PROP_REALTYPE,PROP_CHARTYPE] then
  574.   begin
  575.     EditStr.MaxLength:=CompProp.MaxChars;
  576.     EditStr.Text:=CompProp.PValue;
  577.     CurEdit:=EditStr;
  578.   end
  579.   else If CompProp.EType IN [PROP_BOOLTYPE,PROP_ENUMTYPE,PROP_COLORTYPE,PROP_CURSORTYPE,PROP_MODALTYPE] then
  580.   begin
  581.     ComboEnum.Items.Clear;
  582.     CurEdit:=ComboEnum;
  583.     Case CompProp.EType of
  584.       PROP_BOOLTYPE   ,
  585.       PROP_ENUMTYPE   : If NOT E_GetEnumList(CompProp,ComboEnum.Items) then
  586.                           CurEdit:=Nil;
  587.       PROP_COLORTYPE  : GetColorValues(EGetStrs);
  588.       PROP_CURSORTYPE : GetCursorValues(EGetStrs);
  589.       PROP_MODALTYPE  : For I:=MrNone to MrNo do
  590.                           ComboEnum.Items.Add(MrArray[I]);
  591.     else
  592.       CurEdit:=Nil;
  593.     end;
  594.   end
  595.   else If CompProp.EType = PROP_SETTYPE then
  596.   begin
  597.     If E_GetEnumList(CompProp,SetEdit.Items) then
  598.     begin
  599.       S:=StripAllChr(StripAllChr(StringGrid1.Cells[1,CurRow],'['),']');
  600.       While S<>'' do
  601.       begin
  602.         I:=Pos(',',S);
  603.         If I=0 then
  604.           I:=Succ(Length(S));
  605.         Ts:=Copy(S,1,Pred(I));
  606.         Delete(S,1,I);
  607.         I:=SetEdit.Items.IndexOf(Ts);
  608.         If I>-1 then
  609.           SetEdit.Selected[I]:=True;
  610.       end;
  611.       CurEdit:=SetEdit;
  612.     end;
  613.   end
  614.   else If CompProp.EType IN [PROP_DBIDXNAMETYPE,PROP_DBTABNAMETYPE,
  615.                             PROP_DBNAMETYPE,PROP_DBLOOKUPFIELD] then
  616.   begin
  617.     ComboEnum.Style:=csDropDown;
  618.     If CompProp.EType=PROP_DBNAMETYPE then
  619.       Session.GetDataBaseNames(ComboEnum.Items)
  620.     else If CompProp.EType=PROP_DBIDXNAMETYPE then
  621.     begin
  622.       If GetTableName AND GetDataBaseName then
  623.         If E_GetBoolProp(CurComponent,'Active',TBool) then
  624.         begin
  625.           If NOT TBool then
  626.             If E_SetBoolProp(CurComponent,'Active',True) then
  627.             begin
  628.               Try
  629.                  TTable(CurComponent).IndexDefs.Update;
  630.                  For I := 0 to TTable(CurComponent).IndexDefs.Count - 1 do
  631.                     ComboEnum.Items.Add(TTable(CurComponent).IndexDefs.Items[I].Fields);
  632.               Finally
  633.                  If NOT TBool then
  634.                    E_SetBoolProp(CurComponent,'Active',False);
  635.               end;
  636.             end;
  637.         end;
  638.     end
  639.     else If CompProp.EType=PROP_DBTABNAMETYPE then
  640.     begin
  641.       If GetDataBaseName AND GetDataBasePath then
  642.         GetFileList(S,'*.DB;*.DBF',ComboEnum.Items);
  643.     end
  644.     else If CompProp.EType=PROP_DBLOOKUPFIELD then
  645.     begin
  646.       If GetLookupSource then
  647.       begin
  648.         TBool:=TTable(CAddr).Active;
  649.         If NOT TBool then
  650.           TTable(CAddr).Active:=True;
  651.         For I := 0 to TTable(CAddr).FieldDefs.Count - 1 do
  652.             ComboEnum.Items.Add(TTAble(CAddr).FieldDefs.Items[I].Name);
  653.         If NOT TBool then
  654.           TTable(CAddr).Active:=False;
  655.       end;
  656.     end;
  657.     CurEdit:=ComboEnum;
  658.   end
  659.   else If CompProp.EType=PROP_CLASSTYPE then
  660.   begin
  661.     If CompProp.SubType=PROP_DATASETSUB then
  662.     begin
  663.       ComboEnum.Style:=csDropDown;
  664.       With Session do  for I:= 0 to DatabaseCount - 1 do
  665.         With Databases[I] do
  666.           For J:=0 to DataSetCount-1 do
  667.             If ComboEnum.Items.IndexOf(Datasets[I].Name)<0 then
  668.               ComboEnum.Items.Add(DataSets[I].Name);
  669.       For I:=0 to FComponent.ComponentCount-1 do
  670.          If FComponent.Components[I] IS TTable then
  671.            If ComboEnum.Items.IndexOf(TTable(FComponent.Components[I]).Name)<0 then
  672.              ComboEnum.Items.Add(TTable(FComponent.Components[I]).Name);
  673.       CurEdit:=ComboEnum;
  674.     end
  675.     else If CompProp.SubType=PROP_DATASOURCESUB then
  676.     begin
  677.       ComboEnum.Style:=csDropDown;
  678.       For I:=0 to FComponent.ComponentCount-1 do
  679.          If FComponent.Components[I] IS TDataSource then
  680.            If ComboEnum.Items.IndexOf(TDataSource(FComponent.Components[I]).Name)<0 then
  681.              ComboEnum.Items.Add(TDataSource(FComponent.Components[I]).Name);
  682.       CurEdit:=ComboEnum;
  683.     end;
  684.   end;
  685.   If CurEdit<>Nil then
  686.   begin
  687.     If CurEdit=ComboEnum then
  688.     begin
  689.       ComboEnum.Text:=CompProp.PValue;
  690.       ComboEnum.ItemIndex:=ComboEnum.Items.IndexOf(CompProp.PValue);
  691.     end;
  692.     SetEditBounds(CurEdit);
  693.   end
  694.   else If CompProp.EType=PROP_CLASSTYPE then
  695.   begin
  696.     Try
  697.       If CompProp.SubType=PROP_FONTSUB then
  698.       begin
  699.         FontDialog := TFontDialog.Create(Application);
  700.         try
  701.           FontDialog.Font := TFont(CompProp.ClassAddr);
  702.           FontDialog.Options := FontDialog.Options + [fdForceFontExist];
  703.           if FontDialog.Execute then
  704.             If E_SetIntProp(CurComponent,PropList.Strings[CurRow],LongInt(FontDialog.Font)) then
  705.               CompProp.PValue:=FontDialog.Font.Name;
  706.         finally
  707.           FontDialog.Free;
  708.         end;
  709.       end
  710.       else If CompProp.SubType=PROP_ICONSUB then
  711.       begin
  712.         ImageForm.IconsOnly;
  713.         ImageForm.Image1.Picture.Icon.Assign(TIcon(CompProp.ClassAddr));
  714.         If ImageForm.ShowModal=mrOk then
  715.           TIcon(CompProp.ClassAddr).Assign(ImageForm.Image1.Picture.Icon);
  716.       end
  717.       else If CompProp.SubType=PROP_BMPSUB then
  718.       begin
  719.         DoIt:=UpperCase(StringGrid1.Cells[0,CurRow])='GLYPH';
  720.         ImageForm.BmpsOnly(DoIt);
  721.         ImageForm.Image1.Picture.BitMap.Assign(TBitMap(CompProp.ClassAddr));
  722.         If ImageForm.ShowModal=mrOk then
  723.           TBitMap(CompProp.ClassAddr).Assign(ImageForm.Image1.Picture.BitMap);
  724.         If DoIt then
  725.         begin
  726.           For I := 0 To StringGrid1.RowCount-1 do
  727.             If UpperCase(StringGrid1.Cells[0,I])='NUMGLYPHS' then
  728.             begin
  729.               If E_SetIntProp(CurComponent,StringGrid1.Cells[0,I],StrToInt(ImageForm.UpDownEdit.Text)) then
  730.               begin
  731.                 With PropList.Objects[I] AS TEProperty do
  732.                 begin
  733.                   PValue:=ImageForm.UpdownEdit.Text;
  734.                   StringGrid1.Cells[0,I]:=PValue;
  735.                 end;
  736.               end;
  737.               Break;
  738.             end;
  739.         end;
  740.       end
  741.       else If CompProp.SubType=PROP_TSTRSUB then
  742.       begin
  743.         SedForm.StrList.Lines.Assign(TStrings(CompProp.ClassAddr));
  744.         If (SedForm.ShowModal=mrOk) then
  745.           TStrings(CompProp.ClassAddr).Assign(SedForm.StrList.Lines);
  746.       end
  747.       else If Assigned(TComponent(CompProp.ClassAddr)) then
  748.       begin
  749.         E_GetStrProp(CurComponent,'Name',ts);
  750.         If ts<>'' then
  751.           ts:=ts+'.';
  752.         ts:=ts+StringGrid1.Cells[0,CurRow];
  753.         EditAComponent(TComponent(CompProp.ClassAddr),ts,True);
  754.       end;
  755.       StringGrid1.Cells[1,CurRow]:=CompProp.PValue;
  756.     Finally
  757.     end;
  758.   end;
  759. end;
  760. procedure TCompEditForm.StringGrid1DblClick(Sender: TObject);
  761. Var
  762.     CurCol     : LongInt;
  763.     CurRow     : LongInt;
  764.     MousePoint : TPoint;
  765. begin             {THIS WAS ADDED DUE TO A BUG FOUND BY Wm David Parker}
  766.   GetCursorPos(MousePoint);
  767.   MousePoint:=StringGrid1.ScreenToClient(MousePoint);
  768.   StringGrid1.MouseToCell(MousePoint.X,MousePoint.Y,CurCol,CurRow);
  769.   EditProperty(CurCol,CurRow);
  770. end;
  771.  
  772. procedure TCompEditForm.ClearEdit(Sender: TObject);
  773. begin
  774.   E_SetBoolProp(TComponent(Sender),'Visible',False);
  775.   ActiveControl:=StringGrid1;
  776.   If Sender=ComboEnum then
  777.   begin
  778.     ComboEnum.Items.Clear;
  779.     ComboEnum.Style:=csDropDownList;
  780.   end;
  781.   SetStatusBar(StringGrid1,StringGrid1.Row);
  782. end;
  783. procedure TCompEditForm.FixUpOnExit(Sender: TObject);
  784. Var
  785.     S         : String;
  786.     IsVisible : Boolean;
  787. begin
  788.   If NOT E_GetBoolProp(TComponent(Sender),'Visible',IsVisible) then
  789.     IsVisible:=False;
  790.   If IsVisible AND (PropList<>Nil) then
  791.   begin
  792.     CompProp:=PropList.Objects[StringGrid1.Row] AS TEProperty;
  793.     If CompProp.EType=PROP_SETTYPE then
  794.       S:=''
  795.     else If NOT E_GetStrProp(TComponent(Sender),'Text',S) then
  796.       S:=StringGrid1.Cells[1,StringGrid1.Row];
  797.     Try
  798.       If (S<>StringGrid1.Cells[1,StringGrid1.Row]) then
  799.         DoLastControl;
  800.     Finally
  801.       ClearEdit(Sender);
  802.     end;
  803.   end
  804.   else
  805.     ClearEdit(Sender);
  806. end;
  807.  
  808. procedure TCompEditForm.EditStrKeyPress(Sender: TObject; var Key: Char);
  809. begin
  810.   If StringGrid1.Row>=PropList.Count then
  811.     Exit;
  812.   CompProp:=PropList.Objects[StringGrid1.Row] AS TEProperty;
  813.   Case CompProp.EType Of
  814.     PROP_CHARTYPE : If Key IN ['0'..'9'] then
  815.                       If Pos('#',EditStr.Text)=0 then
  816.                         Key:=#0;
  817.     PROP_INTTYPE  : If (Key='-') AND (CompProp.MinVal>-1) then
  818.                       Key:=#0
  819.                     else If NOT (Key IN ['-','0'..'9']) then
  820.                       Key:=#0;
  821.     PROP_REALTYPE  : If (Key='.') AND (EditStr.Text='') then
  822.                       Key:=#0
  823.                     else If NOT (Key IN ['-','.','0'..'9']) then
  824.                       Key:=#0;
  825.   end;
  826. end;
  827.  
  828.  
  829.  
  830. procedure TCompEditForm.EditkeyDown(Sender: TObject; var Key: Word;
  831.                                     Shift: TShiftState);
  832. Var
  833.      ARow : Integer;
  834. begin
  835.   If Key=VK_ESCAPE then
  836.   begin          {Suggested by Wm David Parker to allow for cancel of edit}
  837.     E_SetBoolProp(TComponent(Sender),'Visible',False);
  838.     Key:=0;
  839.   end
  840.   else If Key IN[VK_UP,VK_DOWN] then
  841.   begin
  842.     If (Sender = ComboEnum) AND (ComboEnum.DroppedDown) then
  843.       Exit;
  844.     With StringGrid1 do
  845.     begin
  846.       ARow:=Row;
  847.       If Key = VK_UP then
  848.       begin
  849.         If (Sender=SetEdit) then With SetEdit do
  850.           If (ItemIndex>0) then
  851.             Exit;
  852.         If Row>0 then
  853.           ARow:=Row-1;
  854.       end
  855.       else If Row<RowCount-1 then
  856.       begin
  857.         If (Sender=SetEdit) then With SetEdit do
  858.           If (ItemIndex>-1) AND (ItemIndex<Items.Count-1) then
  859.             Exit;
  860.         ARow:=Row+1;
  861.       end;
  862.       If ARow<>Row then
  863.       begin
  864.         FixUpOnExit(Sender);
  865.         Row:=ARow;
  866.         Key:=0;
  867.       end;
  868.     end;
  869.   end;
  870. end;
  871. procedure TCompEditForm.StringGrid1KeyPress(    Sender : TObject;
  872.                                             Var Key    : Char);
  873. begin
  874.   If Key=#13 then
  875.   begin
  876.     If (PropList=Nil) OR (StringGrid1.Col<>1) then
  877.       Exit;
  878.     With StringGrid1 do
  879.       EditProperty(Col,Row);
  880.     Key:=#0;
  881.   end;
  882. end;
  883. end.
  884.