|
| 1 | +unit DLG_SCR_ERROR; |
| 2 | + |
| 3 | +interface |
| 4 | + |
| 5 | +uses |
| 6 | + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 | + Dialogs, StdCtrls,script,eval, ComCtrls, ExtCtrls; |
| 8 | + |
| 9 | + |
| 10 | +//function ShowScrError(EpInfo:PEpInfo;scr:pscrInfo;Errmsg:string;texte:string):integer; |
| 11 | +function ShowScrErrDlg(line:integer;msg,scrfile,source:pchar;scrcount,flag:integer):integer; |
| 12 | + |
| 13 | +type |
| 14 | + TE_form = class(TForm) |
| 15 | + Panel1: TPanel; |
| 16 | + Button1: TButton; |
| 17 | + Button2: TButton; |
| 18 | + Button3: TButton; |
| 19 | + Descript_text: TMemo; |
| 20 | + Label1: TLabel; |
| 21 | + Panel2: TPanel; |
| 22 | + detail: TRichEdit; |
| 23 | + StatusBar1: TStatusBar; |
| 24 | + procedure Button3Click(Sender: TObject); |
| 25 | + procedure detailMouseUp(Sender: TObject; Button: TMouseButton; |
| 26 | + Shift: TShiftState; X, Y: Integer); |
| 27 | + procedure detailKeyPress(Sender: TObject; var Key: Char); |
| 28 | + procedure detailChange(Sender: TObject); |
| 29 | + procedure Button2Click(Sender: TObject); |
| 30 | + procedure Panel1Resize(Sender: TObject); |
| 31 | + private |
| 32 | + { Private declarations } |
| 33 | + public |
| 34 | + { Public declarations } |
| 35 | + |
| 36 | + err_pos:integer; |
| 37 | + procedure UpdateCursorPos; |
| 38 | + |
| 39 | + end; |
| 40 | + |
| 41 | +var |
| 42 | + E_form: TE_form; |
| 43 | + lastheight:integer; |
| 44 | +resourcestring |
| 45 | + S_PLUS_DETAIL='Détail >>'; |
| 46 | + S_MIN_DETAIL='<< Détail'; |
| 47 | + E_DESCRIPTION='Erreur d''évaluation à la ligne %d'; |
| 48 | + E_ParseDESCRIPTION='Parsing Error at line %d'; |
| 49 | + |
| 50 | +implementation |
| 51 | + |
| 52 | +{$R *.dfm} |
| 53 | + |
| 54 | +{--------------------------------------- |
| 55 | +affiche une boite de dialogue pour montrer l'erreur dans |
| 56 | +l'expression à l'utilisateur |
| 57 | +->Date:?,revisé:29.07.2008 , 26.04.2011 |
| 58 | +-----------------------------------------} |
| 59 | +function ShowScrErrDlg(line:integer;msg,scrfile,source:pchar;scrcount,flag:integer):integer; |
| 60 | +begin |
| 61 | + E_form.detail.Lines.Clear; |
| 62 | + E_form.detail.Lines.Append(source); |
| 63 | + //showmessage(source); |
| 64 | + e_form.detail.SelStart:=SendMessage(E_form.detail.Handle, EM_LINEINDEX, line-1, 0); |
| 65 | + e_form.detail.SelLength:=SendMessage(E_form.detail.Handle, EM_LINELENGTH, e_form.detail.SelStart, 0); |
| 66 | + //showmessage(inttostr(e_form.detail.SelLength)); |
| 67 | + e_form.detail.SelAttributes.Color:=rgb(255,10,10); |
| 68 | + e_form.detail.SelAttributes.Style:=[fsbold]; |
| 69 | + |
| 70 | + if (flag=1) then |
| 71 | + E_form.label1.caption:=(Format(E_PARSEDESCRIPTION,[line])) |
| 72 | + else |
| 73 | + E_form.label1.caption:=(Format(E_DESCRIPTION,[line])); |
| 74 | + |
| 75 | + E_form.Descript_text.Clear; |
| 76 | + E_form.Descript_text.Lines.Add('>'+E_form.label1.caption+ ' , '+format('source: "%s"',[scrfile])); |
| 77 | + E_Form.Descript_text.Lines.Add(format(':.(line %d) %s',[ line,msg])); |
| 78 | + E_Form.ShowModal; |
| 79 | + |
| 80 | +end; |
| 81 | +(* |
| 82 | +function ShowScrError(EpInfo:PEpInfo;scr:PscrInfo;Errmsg:string;text:string):integer; |
| 83 | +var |
| 84 | + i,a,gpos:integer; html:TstringList;str,str2:string; |
| 85 | + msg:string; |
| 86 | + line,col,scrfilepos:integer; |
| 87 | + source,scrFile:string; |
| 88 | + errScr:PscrInfo; |
| 89 | + nsId:integer; |
| 90 | +begin |
| 91 | +
|
| 92 | + html:=TstringList.Create; |
| 93 | + //E_Form.label1.caption:='Cause:'; |
| 94 | + if (scr.error_namespace=scr.name) then |
| 95 | + begin |
| 96 | + line:=scr.error_line; |
| 97 | + msg:=scr.error_msg ; |
| 98 | + source:=scr.texte; |
| 99 | + scrfile:=scr.scrFileName; |
| 100 | + //showmessage('kjkj single'); |
| 101 | + //showmessage(source); |
| 102 | + end |
| 103 | + else |
| 104 | + begin |
| 105 | + //showmessage('kjkjkjkjkjkjk '+scr.error_namespace); |
| 106 | + errScr:=PScrInfo(namespacelist[indexfromNamespace(scr.error_namespace)]); |
| 107 | + scrfilepos:=errScr.scrFilePos; |
| 108 | + //showmessage(inttostr(errscr.error_line)); |
| 109 | + //showmessage(errscr.Namespace+ ' namespace '+errscr.parentNamespace); |
| 110 | + //showmessage('file name: '+errscr.scrFileName); |
| 111 | + msg:=errScr.error_msg; |
| 112 | + //if errscr.scrFileName='#parent#' then showmessage('file name: '+errscr.scrFileName); |
| 113 | + //showmessage(inttostr(errscr.ParentIndex)); |
| 114 | + line:= errScr.error_line; {ligne uniquement à l'échelle du namespace local} |
| 115 | + while (errscr.scrFileName='#parent#') do |
| 116 | + begin |
| 117 | + nsid:=indexFromNameSpace(errScr.parent); |
| 118 | + if (nsid=-1) then break; |
| 119 | + errScr:=PscrInfo(namespacelist[nsid]); |
| 120 | +
|
| 121 | + end; |
| 122 | + source:=errScr.texte; |
| 123 | + line:=line+xcount_delimiter(#13#10,copy(source,0,scrfilepos)); |
| 124 | + //showmessage(copy(source,0,scrfilepos)); |
| 125 | +
|
| 126 | + scrfile:=errScr.scrFileName; |
| 127 | +
|
| 128 | + end; |
| 129 | + E_form.label1.caption:=(Format(E_DESCRIPTION,[line])); |
| 130 | + if Epinfo=nil then |
| 131 | + E_form.label1.caption:=(Format(E_PARSEDESCRIPTION,[line])); |
| 132 | + E_form.Descript_text.Clear; |
| 133 | + E_form.Descript_text.Lines.Add('>'+E_form.label1.caption+ ' , '+format('source: "%s"',[scrfile])); |
| 134 | +
|
| 135 | + E_Form.Descript_text.Lines.Add(format(':.(line %d) %s',[ line,msg])); |
| 136 | +
|
| 137 | + { |
| 138 | + i:=0; |
| 139 | + html.Text:=scr.texte; |
| 140 | +
|
| 141 | + str:=copy(scr.texte,1,scr.instructions[EpInfo.scr_index].position); |
| 142 | + str:=str+'<strong class="errmsg">'; |
| 143 | + str2:=copy(scr.texte,scr.instructions[EpInfo.scr_index].position,pos(#13#10,html.text)); |
| 144 | + if str2='' then |
| 145 | + str2:=copy(scr.texte,scr.instructions[EpInfo.scr_index].position,+1); |
| 146 | + html.Text:=str+'</strong>'+str2; |
| 147 | + } |
| 148 | +
|
| 149 | + {if (pos(#13#10,str) >0) then a:=pos(#13#10,str) else a:=length(str); |
| 150 | + while(a>0) do |
| 151 | + begin |
| 152 | + html.Text:=html.Text+inttostr(i)+':'+copy(str,1,a); |
| 153 | + inc(i); |
| 154 | + str:=copy(str,a+2,length(str)- a); |
| 155 | + a:=pos(#13#10,str) |
| 156 | + end; |
| 157 | + html.SaveToFile('c:\SCRIPT_SCHEDIT_ERROR.html'); |
| 158 | + E_Form.detail.Lines.LoadFromFile('c:\SCRIPT_SCHEDIT_ERROR.html'); |
| 159 | + } |
| 160 | + //E_Form.detail.Show; |
| 161 | + E_form.detail.Lines.Text:= source; |
| 162 | +
|
| 163 | + //showmessage(source); |
| 164 | +
|
| 165 | + e_form.detail.SelStart:=SendMessage(E_form.detail.Handle, EM_LINEINDEX, line-1, 0); |
| 166 | +
|
| 167 | + e_form.detail.SelLength:=SendMessage(E_form.detail.Handle, EM_LINELENGTH, e_form.detail.SelStart, 0); |
| 168 | + //showmessage(inttostr(e_form.detail.SelLength)); |
| 169 | + e_form.detail.SelAttributes.Color:=rgb(255,10,10); |
| 170 | + e_form.detail.SelAttributes.Style:=[fsbold]; |
| 171 | + //e_form.detail.SelLength:=length(scr.instructions[epInfo.scr_index].text); |
| 172 | + // showmessage('jkjk'); |
| 173 | + if epInfo<>nil then |
| 174 | + e_form.err_pos:=scr.instructions[epInfo.scr.index].position; |
| 175 | + E_Form.ShowModal; |
| 176 | +
|
| 177 | +
|
| 178 | +end; |
| 179 | +*) |
| 180 | + |
| 181 | + |
| 182 | +procedure TE_form.Button3Click(Sender: TObject); |
| 183 | +begin |
| 184 | +detail.SelStart:=err_pos; |
| 185 | +if panel2.Visible then |
| 186 | +detail.SetFocus; |
| 187 | +end; |
| 188 | +procedure TE_Form.UpdateCursorPos; |
| 189 | +var |
| 190 | + CharPos: TPoint; |
| 191 | +begin |
| 192 | + CharPos.Y := SendMessage(detail.Handle, EM_LINEFROMCHAR,detail.SelStart ,0 ); |
| 193 | + CharPos.X := (detail.SelStart - |
| 194 | + SendMessage(detail.Handle, EM_LINEINDEX, CharPos.Y, 0)); |
| 195 | + Inc(CharPos.Y); |
| 196 | + Inc(CharPos.X); |
| 197 | + StatusBar1.Panels[0].Text := Format('line:%d,column:%d', [CharPos.Y, CharPos.X]); |
| 198 | +end; |
| 199 | +procedure TE_form.detailMouseUp(Sender: TObject; Button: TMouseButton; |
| 200 | + Shift: TShiftState; X, Y: Integer); |
| 201 | +begin |
| 202 | + UpdateCursorPos; |
| 203 | +end; |
| 204 | + |
| 205 | +procedure TE_form.detailKeyPress(Sender: TObject; var Key: Char); |
| 206 | +begin |
| 207 | + UpdateCursorPos; |
| 208 | +end; |
| 209 | + |
| 210 | +procedure TE_form.detailChange(Sender: TObject); |
| 211 | +begin |
| 212 | + UpdateCursorPos |
| 213 | +end; |
| 214 | + |
| 215 | +procedure TE_form.Button2Click(Sender: TObject); |
| 216 | +begin |
| 217 | + if panel2.Visible then |
| 218 | + begin |
| 219 | + panel2.Align:=alnone; |
| 220 | + lastheight:=self.ClientHeight; |
| 221 | + self.ClientHeight:=panel1.Height; |
| 222 | + button2.Caption:=S_PLUS_DETAIL; |
| 223 | + |
| 224 | + panel2.Visible:=false; |
| 225 | + end |
| 226 | + else |
| 227 | + begin |
| 228 | + self.ClientHeight:=lastheight; |
| 229 | + panel2.Visible:=true; |
| 230 | + panel2.Align:=alclient; |
| 231 | + button2.Caption:=S_MIN_DETAIL; |
| 232 | + detail.SetFocus; |
| 233 | + end; |
| 234 | + |
| 235 | + |
| 236 | +end; |
| 237 | + |
| 238 | +procedure TE_form.Panel1Resize(Sender: TObject); |
| 239 | +begin |
| 240 | +descript_text.Width:=self.ClientWidth-20; |
| 241 | +button1.Left:=self.ClientWidth-button1.Width-10; |
| 242 | +end; |
| 243 | + |
| 244 | +end. |
0 commit comments