Ignore:
Timestamp:
Jul 7, 2010, 1:44:28 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

Sortable grids, fixed hint-bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/GUI-config/MainU.pas

    r756 r828  
    3737  {$ENDIF}
    3838  Trpcb, //needed for .ptype types
    39   ValEdit;
     39  ValEdit, SortStringGrid;
    4040
    4141type
     
    4949
    5050  TGridInfo = class;  //forward declaration
    51   TGridDataLoader = procedure (GridInfo: TGridInfo) of object; 
     51  TGridDataLoader = procedure (GridInfo: TGridInfo) of object;
    5252  TGridInfo = class (TObject)
    5353  public
    54     Grid      : TStringGrid;  //doesn't own object
     54    Grid      : TSortStringGrid;  //doesn't own object
    5555    FileNum   : string;
    5656    IENS      : string;
     
    6161    ApplyBtn  : TButton;
    6262    RevertBtn : TButton;
    63   end;     
     63  end;
    6464
    6565
     
    7979    Panel5: TPanel;
    8080    ApplicationEvents: TApplicationEvents;
    81     AdvancedUsersGrid: TStringGrid;
    82     BasicUsersGrid: TStringGrid;
     81    AdvancedUsersGrid: TSortStringGrid;
     82    BasicUsersGrid: TSortStringGrid;
    8383    MainMenu: TMainMenu;
    8484    FileMenu: TMenuItem;
     
    9292    SettingsPageControl: TPageControl;
    9393    tsBasicSettings: TTabSheet;
    94     BasicSettingsGrid: TStringGrid;
     94    BasicSettingsGrid: TSortStringGrid;
    9595    tsAdvancedSettings: TTabSheet;
    96     AdvancedSettingsGrid: TStringGrid;
     96    AdvancedSettingsGrid: TSortStringGrid;
    9797    Panel3: TPanel;
    9898    btnSettingsApply: TBitBtn;
     
    108108    PatientsPageControl: TPageControl;
    109109    tsBasicPatients: TTabSheet;
    110     BasicPatientGrid: TStringGrid;
     110    BasicPatientGrid: TSortStringGrid;
    111111    tsAdvancedPatients: TTabSheet;
    112     AdvancedPatientGrid: TStringGrid;
     112    AdvancedPatientGrid: TSortStringGrid;
    113113    Panel9: TPanel;
    114114    btnPatientApply: TBitBtn;
     
    124124    AnyFilePageControl: TPageControl;
    125125    TabSheet2: TTabSheet;
    126     AnyFileGrid: TStringGrid;
     126    AnyFileGrid: TSortStringGrid;
    127127    Panel14: TPanel;
    128128    btnAdvancedApply: TBitBtn;
     
    214214    procedure SetCursorImage(Cursor : TCursor);
    215215    function FileNumForSettingsNode (Node : TTreeNode) : string;
    216     function GetVisibleGrid: TStringGrid;
     216    function GetVisibleGrid: TSortStringGrid;
    217217    function GetVisibleGridInfo : TGridInfo;
    218     function GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
    219     function GetInfoIndexForGrid(Grid : TStringGrid) : integer;
    220     procedure SetVisibleGridIdx(Grid : TStringGrid);
     218    function GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
     219    function GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
     220    procedure SetVisibleGridIdx(Grid : TSortStringGrid);
    221221    procedure GetUsersList(UsersList : TStringList; HideInactive: boolean);
    222222    procedure GetRecordsList(RecordsList : TStringList; FileNum : string);
     
    236236    //procedure GetAnyfileInfo(FileNum : String; IENS : String; Data : TStringList);   
    237237    function FindInStrings(fieldNum : string; Strings : TStringList; var fileNum : string) : integer;
    238     procedure CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
    239     function PostChanges(Grid : TStringGrid) : TModalResult;
     238    procedure CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
     239    function PostChanges(Grid : TSortStringGrid) : TModalResult;
    240240    function PostVisibleGrid: TModalResult;
    241     procedure LoadAnyGrid(Grid : TStringGrid; BasicMode: boolean; FileNum,IENS : string; CurrentData : TStringList);
     241    procedure LoadAnyGrid(Grid : TSortStringGrid; BasicMode: boolean; FileNum,IENS : string; CurrentData : TStringList);
    242242    function DisuserChanged(Changes: TStringList) : boolean;
    243243    procedure DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);
    244244    function DoCloneRecord(FileNum, SourceIENS, New01Field : String) : string;
    245245    function DoCloneUser(SourceIENS, New01Field : String) : string;
    246     function GetGridHint(Grid : TStringGrid; FileNum : string; ACol, ARow : integer) : string;
    247     function FieldHelp(FileNum, FieldNum, HelpStyle : string) : string;   
    248     procedure DoRevert(BasicGrid,AdvancedGrid : TStringGrid);
     246    function GetGridHint(Grid : TSortStringGrid; FileNum : string; ACol, ARow : integer) : string;
     247    function FieldHelp(FileNum, IENS, FieldNum, HelpStyle : string) : string;   
     248    procedure DoRevert(BasicGrid,AdvancedGrid : TSortStringGrid);
    249249  public
    250250    { Public declarations }
     
    252252    LastSelTreeNode : TTreeNode;
    253253    DebugMode : boolean;
    254     function GetUserLine(CurrentUserData : TStringList; Grid : TStringGrid; ARow:integer) :integer;
    255     function GetLineInfo(Grid : TStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
     254    function GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow:integer) :integer;
     255    function GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
    256256    function IsSubFile(FieldDef: string ; var SubFileNum : string) : boolean;
    257257    function IsWPField(FileNum,FieldNum : string) : boolean;
     
    261261    Procedure GetBlankFileInfo(FileNum : string; BlankList : TStringList);
    262262    procedure GetOneRecord(FileNum, IENS : string; Data, BlankFileInfo : TStringList);
    263     procedure AddGridInfo(Grid: TStringGrid; Data : TStringList; BasicMode : boolean;
     263    procedure AddGridInfo(Grid: TSortStringGrid; Data : TStringList; BasicMode : boolean;
    264264                          DataLoader : TGridDataLoader; FileNum : string;
    265265                          ApplyBtn,RevertBtn : TButton);
    266266    procedure LoadAnyGridFromInfo(GridInfo : TGridInfo);
    267     procedure ClearGrid(Grid : TStringGrid);
     267    procedure ClearGrid(Grid : TSortStringGrid);
    268268    procedure RegisterGridInfo(GridInfo : TGridInfo);
    269269    procedure UnRegisterGridInfo(GridInfo : TGridInfo);
     
    398398
    399399 
    400   procedure TMainForm.AddGridInfo(Grid: TStringGrid;
     400  procedure TMainForm.AddGridInfo(Grid: TSortStringGrid;
    401401                                  Data : TStringList;
    402402                                  BasicMode : boolean;
     
    10361036 
    10371037 
    1038   procedure TMainForm.ClearGrid(Grid : TStringGrid);
     1038  procedure TMainForm.ClearGrid(Grid : TSortStringGrid);
    10391039  var i:integer;
    10401040  begin
     
    10481048
    10491049 
    1050   procedure TMainForm.LoadAnyGrid(Grid : TStringGrid;  //the TStringGrid to load
     1050  procedure TMainForm.LoadAnyGrid(Grid : TSortStringGrid;  //the TSortStringGrid to load
    10511051                                  BasicMode: boolean;
    10521052                                  FileNum : string;
     
    10771077  //This assumes that GridInfo already has loaded info.
    10781078  var
    1079     Grid : TStringGrid;  //the TStringGrid to load
     1079    Grid : TSortStringGrid;  //the TSortStringGrid to load
    10801080    BasicMode: boolean;
    10811081    FileNum : string;
     
    10831083    CurrentData : TStringList;
    10841084
    1085     procedure LoadOneLine (Grid : TStringGrid; oneEntry : string; GridRow : integer);
     1085    procedure LoadOneLine (Grid : TSortStringGrid; oneEntry : string; GridRow : integer);
    10861086    var
    10871087      tempFile,IENS : string;
     
    12081208      GridFileNum : string;
    12091209      UserLine : integer;
    1210       Grid : TStringGrid;
     1210      Grid : TSortStringGrid;
    12111211      IEN : int64;
    12121212      IENS : string;
     
    12161216  begin
    12171217    if FLoadingGrid then exit;  //prevent pseudo-clicks during loading...
    1218     Grid := (Sender as TStringGrid);
     1218    Grid := (Sender as TSortStringGrid);
    12191219    GridInfo := GetInfoForGrid(Grid);
    12201220    if GridInfo=nil then exit;
     
    13011301
    13021302
    1303   function TMainForm.GetLineInfo(Grid : TStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
     1303  function TMainForm.GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
    13041304  var fieldNum : string;
    13051305      oneEntry : string;
     
    13271327  end;
    13281328 
    1329   function TMainForm.GetUserLine(CurrentUserData : TStringList; Grid : TStringGrid; ARow: integer) : integer;
     1329  function TMainForm.GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow: integer) : integer;
    13301330  var fieldNum: string;
    13311331      tempFileNum : string;
     
    14291429  end;
    14301430 
    1431   function TMainForm.GetVisibleGrid: TStringGrid;
     1431  function TMainForm.GetVisibleGrid: TSortStringGrid;
    14321432  begin
    14331433    if FVisibleGridIdx > -1 then begin
     
    14381438  end;
    14391439 
    1440   function TMainForm.GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
     1440  function TMainForm.GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
    14411441  var i : integer;
    14421442  begin
     
    14501450
    14511451 
    1452   function TMainForm.GetInfoIndexForGrid(Grid : TStringGrid) : integer;
     1452  function TMainForm.GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
    14531453  var s : string;
    14541454  begin
     
    14571457  end;
    14581458 
    1459   procedure TMainForm.SetVisibleGridIdx(Grid : TStringGrid);
     1459  procedure TMainForm.SetVisibleGridIdx(Grid : TSortStringGrid);
    14601460  begin
    14611461    FVisibleGridIdx := GetInfoIndexForGrid(Grid);
     
    14631463
    14641464
    1465   procedure TMainForm.CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
     1465  procedure TMainForm.CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
    14661466  //Output format:
    14671467  // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
     
    14791479    for row := 1 to Grid.RowCount-1 do begin
    14801480      Entry := GetLineInfo(Grid,CurrentUserData, row);
    1481       //Reject any value containing a "^" , ":" , ";"
     1481      //Reject any value containing a "^"
    14821482      //Do we need an @ here as well?
    1483       if (AnsiPos('^',Entry.newvalue) > 0) or //(AnsiPos(':',Entry.newvalue) > 0) or   //elh Taken out because : used in time
    1484          (AnsiPos(';',Entry.newvalue) > 0)then begin
     1483      if AnsiPos('^',Entry.newvalue) > 0 then begin  //or (AnsiPos(':',Entry.newvalue) > 0) or  (AnsiPos(';',Entry.newvalue) > 0) //elh Taken out because : used in time
    14851484         messagedlg('Invalid value entered for ' + Entry.Fieldname + #13 + #10
    14861485                     + #13 + #10 + 'Invalid Entry:   ' + Entry.newvalue + #13 + #10 +
     
    15141513
    15151514
    1516   function TMainForm.PostChanges(Grid : TStringGrid) : TModalResult;
     1515  function TMainForm.PostChanges(Grid : TSortStringGrid) : TModalResult;
    15171516  //Results:  mrNone -- no post done (not needed)
    15181517  //          mrCancel -- user pressed cancel on confirmation screen.
     
    17291728  end; 
    17301729
    1731   function TMainForm.FieldHelp(FileNum, FieldNum, HelpStyle : string) : string;
     1730  function TMainForm.FieldHelp(FileNum, IENS, FieldNum, HelpStyle : string) : string;
    17321731  var
    17331732     RPCResult: string;
     
    17371736  begin
    17381737    Result := '';
    1739     SrchStr := FileNum + '^' + FieldNum + '^' + HelpStyle;
     1738    SrchStr := FileNum + '^' + FieldNum + '^' + HelpStyle + '^' + IENS;
    17401739    Idx := CachedHelpIdx.IndexOf(SrchStr);
    17411740    if Idx = -1 then begin
     
    17751774  end;
    17761775
    1777   function TMainForm.GetGridHint(Grid : TStringGrid; FileNum : string; ACol, ARow : integer) : string;
     1776  function TMainForm.GetGridHint(Grid : TSortStringGrid; FileNum : string; ACol, ARow : integer) : string;
    17781777  var fieldNum : string;
     1778      GridInfo : TGridInfo;
    17791779  begin
    17801780    Result := '';
    17811781    //Result := 'Row=' + IntToStr(ARow) + ', Col='+ IntToStr(ACol);
    17821782    if ARow > Grid.RowCount-1 then exit;
    1783     if (ARow < 0) or (ACol < 0) then exit;
     1783    if (ARow < 1) or (ACol < 0) then exit;
    17841784    if ACol=0 then begin
    1785       Result := 'This is the database field NUMBER';     
     1785      Result := 'This is the database field NUMBER';
    17861786    end else if ACol=1 then begin
    1787       Result := 'This is the database field NAME';     
     1787      Result := 'This is the database field NAME';
    17881788    end else begin
    17891789      fieldNum := Grid.Cells[0,ARow];
     
    17971797        result := 'Clicking will open new window...';
    17981798      end else begin
    1799         Result := FieldHelp(FileNum, fieldNum, '?');     
    1800       end; 
     1799        GridInfo := GetInfoForGrid(Grid);
     1800        Result := FieldHelp(FileNum,  GridInfo.IENS, fieldNum, '?');
     1801      end;
    18011802    end;
    18021803  end;
     
    18301831    if VisibleGridInfo = nil then exit;
    18311832    if VisibleGridInfo.Grid = nil then exit;
    1832     if (ClassName='TStringGrid') then begin     
     1833    if (ClassName='TSortStringGrid') then begin     
    18331834      VisibleGridInfo.Grid.MouseToCell(Pos.X,Pos.Y,ACol,ARow);
    18341835      HintInfo.HintStr := GetGridHint(VisibleGridInfo.Grid,VisibleGridInfo.FileNum,ACol, ARow);
     
    19691970    ModalResult := PostVisibleGrid;
    19701971    if ModalResult = mrNo then exit;
    1971     FileNum := FileORComboBox.ItemID; 
     1972    FileNum := FileORComboBox.ItemID;
    19721973    IEN := RecordORComboBox.ItemID;  //get info from selected record
    19731974    if IEN=0 then exit;
     
    21932194
    21942195
    2195   procedure TMainForm.DoRevert(BasicGrid,AdvancedGrid : TStringGrid);
     2196  procedure TMainForm.DoRevert(BasicGrid,AdvancedGrid : TSortStringGrid);
    21962197  //BasicGrid doesn't have to be supplied.  Can be nil value.
    21972198  //AdvancedGrid is required.
Note: See TracChangeset for help on using the changeset viewer.