| [541] | 1 | unit LookupU; | 
|---|
|  | 2 | (* | 
|---|
|  | 3 | WorldVistA Configuration Utility | 
|---|
|  | 4 | (c) 8/2008 Kevin Toppenberg | 
|---|
|  | 5 | Programmed by Kevin Toppenberg, Eddie Hagood | 
|---|
|  | 6 |  | 
|---|
|  | 7 | Family Physicians of Greeneville, PC | 
|---|
|  | 8 | 1410 Tusculum Blvd, Suite 2600 | 
|---|
|  | 9 | Greeneville, TN 37745 | 
|---|
|  | 10 | kdtop@yahoo.com | 
|---|
|  | 11 |  | 
|---|
|  | 12 | This library is free software; you can redistribute it and/or | 
|---|
|  | 13 | modify it under the terms of the GNU Lesser General Public | 
|---|
|  | 14 | License as published by the Free Software Foundation; either | 
|---|
|  | 15 | version 2.1 of the License, or (at your option) any later version. | 
|---|
|  | 16 |  | 
|---|
|  | 17 | This library is distributed in the hope that it will be useful, | 
|---|
|  | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
|  | 20 | Lesser General Public License for more details. | 
|---|
|  | 21 |  | 
|---|
|  | 22 | You should have received a copy of the GNU Lesser General Public | 
|---|
|  | 23 | License along with this library; if not, write to the Free Software | 
|---|
|  | 24 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
|---|
|  | 25 | *) | 
|---|
|  | 26 |  | 
|---|
|  | 27 | interface | 
|---|
|  | 28 |  | 
|---|
|  | 29 | uses | 
|---|
|  | 30 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
|---|
|  | 31 | Dialogs, StdCtrls, ORCtrls, Buttons; | 
|---|
|  | 32 |  | 
|---|
|  | 33 | type | 
|---|
|  | 34 | TFieldLookupForm = class(TForm) | 
|---|
|  | 35 | ORComboBox: TORComboBox; | 
|---|
|  | 36 | OKBtn: TBitBtn; | 
|---|
|  | 37 | CancelBtn: TBitBtn; | 
|---|
|  | 38 | procedure ORComboBoxNeedData(Sender: TObject; const StartFrom: String; | 
|---|
|  | 39 | Direction, InsertAt: Integer); | 
|---|
|  | 40 | procedure FormShow(Sender: TObject); | 
|---|
|  | 41 | procedure ORComboBoxDblClick(Sender: TObject); | 
|---|
|  | 42 | private | 
|---|
|  | 43 | { Private declarations } | 
|---|
|  | 44 | FFileNum : String; | 
|---|
|  | 45 |  | 
|---|
|  | 46 | public | 
|---|
|  | 47 | { Public declarations } | 
|---|
|  | 48 | procedure InitORComboBox(ORComboBox: TORComboBox; initValue : string); | 
|---|
|  | 49 | procedure PrepForm(FileNum,InitValue : string); | 
|---|
|  | 50 | function SubSetOfFile(FileNum: string; const StartFrom: string; | 
|---|
|  | 51 | Direction: Integer): TStrings; | 
|---|
|  | 52 | end; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | var | 
|---|
|  | 55 | FieldLookupForm: TFieldLookupForm; | 
|---|
|  | 56 |  | 
|---|
|  | 57 | implementation | 
|---|
|  | 58 |  | 
|---|
|  | 59 | uses | 
|---|
|  | 60 | ORNet, ORFn, | 
|---|
|  | 61 | Trpcb,   //needed for .ptype types | 
|---|
|  | 62 | QControls, fPtDemoEdit; | 
|---|
|  | 63 | {$R *.dfm} | 
|---|
|  | 64 |  | 
|---|
|  | 65 | procedure TFieldLookupForm.ORComboBoxNeedData(Sender: TObject; | 
|---|
|  | 66 | const StartFrom: String; | 
|---|
|  | 67 | Direction, InsertAt: Integer); | 
|---|
|  | 68 | var | 
|---|
|  | 69 | Result : TStrings; | 
|---|
|  | 70 | begin | 
|---|
|  | 71 | Result := SubSetOfFile(FFileNum, StartFrom, Direction); | 
|---|
|  | 72 | TORComboBox(Sender).ForDataUse(Result); | 
|---|
|  | 73 | end; | 
|---|
|  | 74 |  | 
|---|
|  | 75 | procedure TFieldLookupForm.InitORComboBox(ORComboBox: TORComboBox; initValue : string); | 
|---|
|  | 76 | begin | 
|---|
|  | 77 | ORComboBox.Text := initValue; | 
|---|
|  | 78 | ORComboBox.InitLongList(initValue); | 
|---|
|  | 79 | if ORComboBox.Items.Count > 0 then begin | 
|---|
|  | 80 | ORComboBox.Text := Piece(ORComboBox.Items[0],'^',2); | 
|---|
|  | 81 | end else begin | 
|---|
|  | 82 | ORComboBox.Text := '<Start Typing to Search>'; | 
|---|
|  | 83 | end; | 
|---|
|  | 84 | end; | 
|---|
|  | 85 |  | 
|---|
|  | 86 | procedure TFieldLookupForm.PrepForm(FileNum,InitValue : string); | 
|---|
|  | 87 | begin | 
|---|
|  | 88 | FFileNum := FileNum; | 
|---|
|  | 89 | Self.Caption := 'Pick Entry from File # ' + FileNum; | 
|---|
|  | 90 | //if (FileNum='200') and (InitValue='') then begin | 
|---|
|  | 91 | //  InitValue := fPtDemoEdit.CurrentUserName; | 
|---|
|  | 92 | //end; | 
|---|
|  | 93 | InitORComboBox(ORComboBox,InitValue); | 
|---|
|  | 94 | end; | 
|---|
|  | 95 |  | 
|---|
|  | 96 |  | 
|---|
|  | 97 | function TFieldLookupForm.SubSetOfFile(FileNum: string; | 
|---|
|  | 98 | const StartFrom: string; | 
|---|
|  | 99 | Direction: Integer       ): TStrings; | 
|---|
|  | 100 |  | 
|---|
|  | 101 | { returns a pointer to a list of file entries (for use in a long list box) - | 
|---|
|  | 102 | The return value is a pointer to RPCBrokerV.Results, so the data must | 
|---|
|  | 103 | be used BEFORE the next broker call! } | 
|---|
|  | 104 | var | 
|---|
|  | 105 | cmd,RPCResult : string; | 
|---|
|  | 106 | begin | 
|---|
|  | 107 | RPCBrokerV.remoteprocedure := 'TMG CHANNEL'; | 
|---|
|  | 108 | RPCBrokerV.Param[0].Value := '.X';  // not used | 
|---|
|  | 109 | RPCBrokerV.param[0].ptype := list; | 
|---|
|  | 110 | cmd := 'FILE ENTRY SUBSET'; | 
|---|
|  | 111 | cmd := cmd + '^' + FileNum + '^' + StartFrom + '^' + IntToStr(Direction); | 
|---|
|  | 112 | RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd; | 
|---|
|  | 113 | RPCBrokerV.Call; | 
|---|
|  | 114 | RPCResult := RPCBrokerV.Results[0];    //returns:  error: -1;  success=1 | 
|---|
|  | 115 | if piece(RPCResult,'^',1)='-1' then begin | 
|---|
|  | 116 | // handle error... | 
|---|
|  | 117 | end else begin | 
|---|
|  | 118 | RPCBrokerV.Results.Delete(0); | 
|---|
|  | 119 | if RPCBrokerV.Results.Count=0 then begin | 
|---|
|  | 120 | //RPCBrokerV.Results.Add('0^<NO DATA>'); | 
|---|
|  | 121 | end; | 
|---|
|  | 122 | end; | 
|---|
|  | 123 | Result := RPCBrokerV.Results; | 
|---|
|  | 124 | end; | 
|---|
|  | 125 |  | 
|---|
|  | 126 | procedure TFieldLookupForm.FormShow(Sender: TObject); | 
|---|
|  | 127 | var mousePos : TPoint; | 
|---|
|  | 128 | begin | 
|---|
|  | 129 | GetCursorPos(mousePos); | 
|---|
|  | 130 | with FieldLookupForm do begin | 
|---|
|  | 131 | Top := mousePos.Y - 39; | 
|---|
|  | 132 | Left := mousePos.X - 15; | 
|---|
|  | 133 | if Left + Width > Screen.DesktopWidth then begin | 
|---|
|  | 134 | Left := Screen.DesktopWidth - Width; | 
|---|
|  | 135 | end; | 
|---|
|  | 136 | end; | 
|---|
|  | 137 | //    ORComboBox.DroppedDown := true; | 
|---|
|  | 138 | end; | 
|---|
|  | 139 |  | 
|---|
|  | 140 |  | 
|---|
|  | 141 | procedure TFieldLookupForm.ORComboBoxDblClick(Sender: TObject); | 
|---|
|  | 142 | begin | 
|---|
|  | 143 | Modalresult := mrOK;  //Close form, item should be selected (?) | 
|---|
|  | 144 | end; | 
|---|
|  | 145 |  | 
|---|
|  | 146 | end. | 
|---|
|  | 147 |  | 
|---|