Index: cprs/branches/GUI-config/MainU.pas
===================================================================
--- cprs/branches/GUI-config/MainU.pas	(revision 756)
+++ cprs/branches/GUI-config/MainU.pas	(revision 828)
@@ -37,5 +37,5 @@
   {$ENDIF}
   Trpcb, //needed for .ptype types
-  ValEdit;
+  ValEdit, SortStringGrid;
 
 type
@@ -49,8 +49,8 @@
 
   TGridInfo = class;  //forward declaration
-  TGridDataLoader = procedure (GridInfo: TGridInfo) of object;  
+  TGridDataLoader = procedure (GridInfo: TGridInfo) of object;
   TGridInfo = class (TObject)
   public
-    Grid      : TStringGrid;  //doesn't own object
+    Grid      : TSortStringGrid;  //doesn't own object
     FileNum   : string;
     IENS      : string;
@@ -61,5 +61,5 @@
     ApplyBtn  : TButton;
     RevertBtn : TButton;
-  end;      
+  end;
 
 
@@ -79,6 +79,6 @@
     Panel5: TPanel;
     ApplicationEvents: TApplicationEvents;
-    AdvancedUsersGrid: TStringGrid;
-    BasicUsersGrid: TStringGrid;
+    AdvancedUsersGrid: TSortStringGrid;
+    BasicUsersGrid: TSortStringGrid;
     MainMenu: TMainMenu;
     FileMenu: TMenuItem;
@@ -92,7 +92,7 @@
     SettingsPageControl: TPageControl;
     tsBasicSettings: TTabSheet;
-    BasicSettingsGrid: TStringGrid;
+    BasicSettingsGrid: TSortStringGrid;
     tsAdvancedSettings: TTabSheet;
-    AdvancedSettingsGrid: TStringGrid;
+    AdvancedSettingsGrid: TSortStringGrid;
     Panel3: TPanel;
     btnSettingsApply: TBitBtn;
@@ -108,7 +108,7 @@
     PatientsPageControl: TPageControl;
     tsBasicPatients: TTabSheet;
-    BasicPatientGrid: TStringGrid;
+    BasicPatientGrid: TSortStringGrid;
     tsAdvancedPatients: TTabSheet;
-    AdvancedPatientGrid: TStringGrid;
+    AdvancedPatientGrid: TSortStringGrid;
     Panel9: TPanel;
     btnPatientApply: TBitBtn;
@@ -124,5 +124,5 @@
     AnyFilePageControl: TPageControl;
     TabSheet2: TTabSheet;
-    AnyFileGrid: TStringGrid;
+    AnyFileGrid: TSortStringGrid;
     Panel14: TPanel;
     btnAdvancedApply: TBitBtn;
@@ -214,9 +214,9 @@
     procedure SetCursorImage(Cursor : TCursor);
     function FileNumForSettingsNode (Node : TTreeNode) : string;
-    function GetVisibleGrid: TStringGrid;
+    function GetVisibleGrid: TSortStringGrid;
     function GetVisibleGridInfo : TGridInfo;
-    function GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
-    function GetInfoIndexForGrid(Grid : TStringGrid) : integer;
-    procedure SetVisibleGridIdx(Grid : TStringGrid);
+    function GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
+    function GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
+    procedure SetVisibleGridIdx(Grid : TSortStringGrid);
     procedure GetUsersList(UsersList : TStringList; HideInactive: boolean);
     procedure GetRecordsList(RecordsList : TStringList; FileNum : string);
@@ -236,15 +236,15 @@
     //procedure GetAnyfileInfo(FileNum : String; IENS : String; Data : TStringList);   
     function FindInStrings(fieldNum : string; Strings : TStringList; var fileNum : string) : integer;
-    procedure CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
-    function PostChanges(Grid : TStringGrid) : TModalResult;
+    procedure CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
+    function PostChanges(Grid : TSortStringGrid) : TModalResult;
     function PostVisibleGrid: TModalResult;
-    procedure LoadAnyGrid(Grid : TStringGrid; BasicMode: boolean; FileNum,IENS : string; CurrentData : TStringList);
+    procedure LoadAnyGrid(Grid : TSortStringGrid; BasicMode: boolean; FileNum,IENS : string; CurrentData : TStringList);
     function DisuserChanged(Changes: TStringList) : boolean;
     procedure DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);
     function DoCloneRecord(FileNum, SourceIENS, New01Field : String) : string;
     function DoCloneUser(SourceIENS, New01Field : String) : string;
-    function GetGridHint(Grid : TStringGrid; FileNum : string; ACol, ARow : integer) : string;
-    function FieldHelp(FileNum, FieldNum, HelpStyle : string) : string;    
-    procedure DoRevert(BasicGrid,AdvancedGrid : TStringGrid);
+    function GetGridHint(Grid : TSortStringGrid; FileNum : string; ACol, ARow : integer) : string;
+    function FieldHelp(FileNum, IENS, FieldNum, HelpStyle : string) : string;    
+    procedure DoRevert(BasicGrid,AdvancedGrid : TSortStringGrid);
   public
     { Public declarations }
@@ -252,6 +252,6 @@
     LastSelTreeNode : TTreeNode;
     DebugMode : boolean;
-    function GetUserLine(CurrentUserData : TStringList; Grid : TStringGrid; ARow:integer) :integer;
-    function GetLineInfo(Grid : TStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
+    function GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow:integer) :integer;
+    function GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
     function IsSubFile(FieldDef: string ; var SubFileNum : string) : boolean;
     function IsWPField(FileNum,FieldNum : string) : boolean;
@@ -261,9 +261,9 @@
     Procedure GetBlankFileInfo(FileNum : string; BlankList : TStringList);
     procedure GetOneRecord(FileNum, IENS : string; Data, BlankFileInfo : TStringList);
-    procedure AddGridInfo(Grid: TStringGrid; Data : TStringList; BasicMode : boolean; 
+    procedure AddGridInfo(Grid: TSortStringGrid; Data : TStringList; BasicMode : boolean; 
                           DataLoader : TGridDataLoader; FileNum : string;
                           ApplyBtn,RevertBtn : TButton);
     procedure LoadAnyGridFromInfo(GridInfo : TGridInfo);
-    procedure ClearGrid(Grid : TStringGrid);
+    procedure ClearGrid(Grid : TSortStringGrid);
     procedure RegisterGridInfo(GridInfo : TGridInfo);
     procedure UnRegisterGridInfo(GridInfo : TGridInfo);
@@ -398,5 +398,5 @@
 
   
-  procedure TMainForm.AddGridInfo(Grid: TStringGrid; 
+  procedure TMainForm.AddGridInfo(Grid: TSortStringGrid; 
                                   Data : TStringList; 
                                   BasicMode : boolean;
@@ -1036,5 +1036,5 @@
   
   
-  procedure TMainForm.ClearGrid(Grid : TStringGrid);
+  procedure TMainForm.ClearGrid(Grid : TSortStringGrid);
   var i:integer;
   begin
@@ -1048,5 +1048,5 @@
 
   
-  procedure TMainForm.LoadAnyGrid(Grid : TStringGrid;  //the TStringGrid to load
+  procedure TMainForm.LoadAnyGrid(Grid : TSortStringGrid;  //the TSortStringGrid to load
                                   BasicMode: boolean; 
                                   FileNum : string; 
@@ -1077,5 +1077,5 @@
   //This assumes that GridInfo already has loaded info.
   var
-    Grid : TStringGrid;  //the TStringGrid to load
+    Grid : TSortStringGrid;  //the TSortStringGrid to load
     BasicMode: boolean; 
     FileNum : string; 
@@ -1083,5 +1083,5 @@
     CurrentData : TStringList;
 
-    procedure LoadOneLine (Grid : TStringGrid; oneEntry : string; GridRow : integer);
+    procedure LoadOneLine (Grid : TSortStringGrid; oneEntry : string; GridRow : integer);
     var
       tempFile,IENS : string;
@@ -1208,5 +1208,5 @@
       GridFileNum : string;
       UserLine : integer;
-      Grid : TStringGrid;
+      Grid : TSortStringGrid;
       IEN : int64;
       IENS : string;
@@ -1216,5 +1216,5 @@
   begin
     if FLoadingGrid then exit;  //prevent pseudo-clicks during loading...
-    Grid := (Sender as TStringGrid);
+    Grid := (Sender as TSortStringGrid);
     GridInfo := GetInfoForGrid(Grid);
     if GridInfo=nil then exit;
@@ -1301,5 +1301,5 @@
 
 
-  function TMainForm.GetLineInfo(Grid : TStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
+  function TMainForm.GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
   var fieldNum : string;
       oneEntry : string;
@@ -1327,5 +1327,5 @@
   end;
   
-  function TMainForm.GetUserLine(CurrentUserData : TStringList; Grid : TStringGrid; ARow: integer) : integer;
+  function TMainForm.GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow: integer) : integer;
   var fieldNum: string;
       tempFileNum : string;
@@ -1429,5 +1429,5 @@
   end;
   
-  function TMainForm.GetVisibleGrid: TStringGrid;
+  function TMainForm.GetVisibleGrid: TSortStringGrid;
   begin
     if FVisibleGridIdx > -1 then begin 
@@ -1438,5 +1438,5 @@
   end;
   
-  function TMainForm.GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
+  function TMainForm.GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
   var i : integer;
   begin
@@ -1450,5 +1450,5 @@
 
   
-  function TMainForm.GetInfoIndexForGrid(Grid : TStringGrid) : integer;
+  function TMainForm.GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
   var s : string;
   begin
@@ -1457,5 +1457,5 @@
   end;
   
-  procedure TMainForm.SetVisibleGridIdx(Grid : TStringGrid);
+  procedure TMainForm.SetVisibleGridIdx(Grid : TSortStringGrid);
   begin
     FVisibleGridIdx := GetInfoIndexForGrid(Grid);
@@ -1463,5 +1463,5 @@
 
 
-  procedure TMainForm.CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
+  procedure TMainForm.CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
   //Output format:
   // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
@@ -1479,8 +1479,7 @@
     for row := 1 to Grid.RowCount-1 do begin
       Entry := GetLineInfo(Grid,CurrentUserData, row);
-      //Reject any value containing a "^" , ":" , ";"
+      //Reject any value containing a "^"
       //Do we need an @ here as well?
-      if (AnsiPos('^',Entry.newvalue) > 0) or //(AnsiPos(':',Entry.newvalue) > 0) or   //elh Taken out because : used in time
-         (AnsiPos(';',Entry.newvalue) > 0)then begin
+      if AnsiPos('^',Entry.newvalue) > 0 then begin  //or (AnsiPos(':',Entry.newvalue) > 0) or  (AnsiPos(';',Entry.newvalue) > 0) //elh Taken out because : used in time
          messagedlg('Invalid value entered for ' + Entry.Fieldname + #13 + #10
                      + #13 + #10 + 'Invalid Entry:   ' + Entry.newvalue + #13 + #10 +
@@ -1514,5 +1513,5 @@
 
 
-  function TMainForm.PostChanges(Grid : TStringGrid) : TModalResult;
+  function TMainForm.PostChanges(Grid : TSortStringGrid) : TModalResult;
   //Results:  mrNone -- no post done (not needed)
   //          mrCancel -- user pressed cancel on confirmation screen.
@@ -1729,5 +1728,5 @@
   end;  
 
-  function TMainForm.FieldHelp(FileNum, FieldNum, HelpStyle : string) : string;
+  function TMainForm.FieldHelp(FileNum, IENS, FieldNum, HelpStyle : string) : string;
   var
      RPCResult: string;
@@ -1737,5 +1736,5 @@
   begin
     Result := '';
-    SrchStr := FileNum + '^' + FieldNum + '^' + HelpStyle;
+    SrchStr := FileNum + '^' + FieldNum + '^' + HelpStyle + '^' + IENS;
     Idx := CachedHelpIdx.IndexOf(SrchStr);
     if Idx = -1 then begin
@@ -1775,15 +1774,16 @@
   end;
 
-  function TMainForm.GetGridHint(Grid : TStringGrid; FileNum : string; ACol, ARow : integer) : string;
+  function TMainForm.GetGridHint(Grid : TSortStringGrid; FileNum : string; ACol, ARow : integer) : string;
   var fieldNum : string;
+      GridInfo : TGridInfo;
   begin
     Result := '';
     //Result := 'Row=' + IntToStr(ARow) + ', Col='+ IntToStr(ACol);
     if ARow > Grid.RowCount-1 then exit;
-    if (ARow < 0) or (ACol < 0) then exit;
+    if (ARow < 1) or (ACol < 0) then exit;
     if ACol=0 then begin
-      Result := 'This is the database field NUMBER';      
+      Result := 'This is the database field NUMBER';
     end else if ACol=1 then begin
-      Result := 'This is the database field NAME';      
+      Result := 'This is the database field NAME';
     end else begin
       fieldNum := Grid.Cells[0,ARow];
@@ -1797,6 +1797,7 @@
         result := 'Clicking will open new window...';
       end else begin
-        Result := FieldHelp(FileNum, fieldNum, '?');      
-      end;  
+        GridInfo := GetInfoForGrid(Grid);
+        Result := FieldHelp(FileNum,  GridInfo.IENS, fieldNum, '?');
+      end;
     end;
   end;
@@ -1830,5 +1831,5 @@
     if VisibleGridInfo = nil then exit;
     if VisibleGridInfo.Grid = nil then exit;
-    if (ClassName='TStringGrid') then begin      
+    if (ClassName='TSortStringGrid') then begin      
       VisibleGridInfo.Grid.MouseToCell(Pos.X,Pos.Y,ACol,ARow);
       HintInfo.HintStr := GetGridHint(VisibleGridInfo.Grid,VisibleGridInfo.FileNum,ACol, ARow);
@@ -1969,5 +1970,5 @@
     ModalResult := PostVisibleGrid;
     if ModalResult = mrNo then exit;
-    FileNum := FileORComboBox.ItemID;  
+    FileNum := FileORComboBox.ItemID;
     IEN := RecordORComboBox.ItemID;  //get info from selected record
     if IEN=0 then exit;
@@ -2193,5 +2194,5 @@
 
 
-  procedure TMainForm.DoRevert(BasicGrid,AdvancedGrid : TStringGrid);
+  procedure TMainForm.DoRevert(BasicGrid,AdvancedGrid : TSortStringGrid);
   //BasicGrid doesn't have to be supplied.  Can be nil value.
   //AdvancedGrid is required.
