Changeset 809 for cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
- Timestamp:
- Jun 22, 2010, 8:22:30 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
r793 r809 18 18 URL_CPRSDir : string; //This is CPRSDir, but all '\'s are converted to '/'s 19 19 20 CONST ALT_IMG_TAG_CONVERT = 'alt="convert to $CPRSDIR$"'; 20 CONST 21 CPRS_DIR_SIGNAL = '$CPRSDIR$'; 22 CPRS_CACHE_DIR_SIGNAL = CPRS_DIR_SIGNAL+'\Cache\'; 23 ALT_IMG_TAG_CONVERT = 'alt="convert to ' + CPRS_DIR_SIGNAL +'"'; 21 24 22 25 procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string; … … 43 46 Procedure ScanForSubs(Lines : TStrings); 44 47 Procedure InsertSubs(Lines : TStrings); 48 function HTTPEncode(const AStr: string): string; 45 49 46 50 implementation … … 217 221 SubsFoundList.Clear; 218 222 for i := 0 to Lines.Count-1 do begin 219 p := Pos( '$CPRSDIR$',Lines.Strings[i]);223 p := Pos(CPRS_DIR_SIGNAL,Lines.Strings[i]); 220 224 if p>0 then begin 221 p := p + Length( '$CPRSDIR$\Cache\');225 p := p + Length(CPRS_CACHE_DIR_SIGNAL); 222 226 p2 := PosEx('"',Lines.Strings[i],p); 223 227 tempS := MidStr(Lines.Strings[i],p,(p2-p)); 224 228 SubsFoundList.Add(tempS); 225 229 if Pos('file:///',Lines.Strings[i]) > 0 then begin 226 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i], '$CPRSDIR$',URL_CPRSDir);230 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],CPRS_DIR_SIGNAL,URL_CPRSDir); 227 231 end else begin 228 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i], '$CPRSDIR$',CPRSDir);232 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],CPRS_DIR_SIGNAL,CPRSDir); 229 233 end; 230 234 //Ensure images are downloaded before passing page to web browser … … 237 241 Procedure InsertSubs(Lines : TStrings); 238 242 //Purpose: To scan a edited note images, and replace references to CPRS's 239 // actual local directory with $CPRS$243 // actual local directory with CPRS_DIR_SIGNAL ('$CPRSDIR$') 240 244 var i,p : integer; 241 245 TempS: string; … … 243 247 begin 244 248 for i := 0 to Lines.Count-1 do begin 245 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],URL_CPRSDir,'$CPRSDIR$'); 249 p := pos(ALT_IMG_TAG_CONVERT,Lines.Strings[i]); 250 if p = 0 then continue; 251 TempS := Lines.Strings[i]; 252 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],URL_CPRSDir,CPRS_DIR_SIGNAL); 253 if Lines.Strings[i] = TempS then begin //There is a problem. Replacement failed. 254 MessageDlg('Problem converting image path to $CPRSDIR$',mtWarning,[mbOK],0); 255 end; 256 //TempS := MidStr(Lines.Strings[i],1,p-1); 257 //TempS := TempS + MidStr(Lines.Strings[i],p+length(ALT_IMG_TAG_CONVERT),length(Lines.Strings[i])+1); 258 //Lines.Strings[i] := TempS; 246 259 Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],ALT_IMG_TAG_CONVERT,'IMAGE'); //Remove signal 247 p := pos(ALT_IMG_TAG_CONVERT,Lines.Strings[i]);248 if p > 0 then begin249 TempS := MidStr(Lines.Strings[i],1,p-1);250 TempS := TempS + MidStr(Lines.Strings[i],p+length(ALT_IMG_TAG_CONVERT),length(Lines.Strings[i])+1);251 Lines.Strings[i] := TempS;252 end;253 260 end; 254 261 end; … … 504 511 Result := AnsiReplaceText(Result,'>'+CRLF,'>'#$1F); //protect sequences we want 505 512 Result := AnsiReplaceText(Result,CRLF,'<BR>'+CRLF); //Add <BR>'s to CrLf's 506 Result := AnsiReplaceText(Result,'>'#$1F,'> '+CRLF); //Restore sequences we wanted513 Result := AnsiReplaceText(Result,'>'#$1F,'><BR>'+CRLF); //Restore sequences we wanted 507 514 Result := AnsiReplaceText(Result,#$1E,'<NO DATA>'); //Restore sequences we wanted 508 515 end; … … 829 836 //elh 6/19/09 830 837 begin 831 if not assigned(Reg) then Reg := TRegistry.Create; 838 if not assigned(Reg) then begin 839 Reg := TRegistry.Create; 840 Reg.Rootkey := HKEY_CURRENT_USER; 841 Reg.OpenKey('\Software\Microsoft\Internet Explorer\PageSetup', False) 842 end; 832 843 try 833 844 StoredIEFooters := '&u&b&d'; //Comment this line to restore previous value … … 853 864 s := Piece(Lines.Strings[i],'DATE OF NOTE:',2); 854 865 s := Piece(s,'@',1); 855 Result := Trim(s); 856 end; 857 end; 866 Result := Trim(s); 867 end; 868 end; 869 870 function HTTPEncode(const AStr: string): string; 871 //NOTE: routine from here: 872 // http://www.delphitricks.com/source-code/internet/encode_a_http_url.html 873 //NOTE: I modified this to my purposes. I removed conversion of '/',':' 874 const 875 //kt original --> NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '.', '_', '-']; 876 NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '.', '_', '-', '/', ':']; //kt 877 var 878 Sp, Rp: PChar; 879 begin 880 SetLength(Result, Length(AStr) * 3); 881 Sp := PChar(AStr); 882 Rp := PChar(Result); 883 while Sp^ <> #0 do begin 884 if Sp^ in NoConversion then 885 Rp^ := Sp^ 886 //kt else if Sp^ = ' ' then 887 //kt Rp^ := '+' 888 else begin 889 FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]); 890 Inc(Rp, 2); 891 end; 892 Inc(Rp); 893 Inc(Sp); 894 end; 895 SetLength(Result, Rp - PChar(Result)); 896 end; 897 858 898 859 899 //=============================================================== … … 883 923 RestorePrinterTimer.Enabled := false; 884 924 RestoreIEPrinting; {elh 6/19/09} //kt 885 //kt SetDefaultPrinter(SavedDefaultPrinter); 925 //kt SetDefaultPrinter(SavedDefaultPrinter); 886 926 //beep; 887 end; 927 end; 888 928 889 929 //=============================================================== 890 930 931 function EncodePath(var Path : string) : string; 932 begin 933 Result := AnsiReplaceStr(Path,'\','/'); 934 Result := HTTPEncode(Result); 935 end; 891 936 892 937 initialization … … 894 939 PrinterEvents := TPrinterEvents.Create; 895 940 CPRSDir := ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))); 896 URL_CPRSDir := AnsiReplaceStr(CPRSDir,'\','/');941 URL_CPRSDir := EncodePath(CPRSDir); 897 942 SubsFoundList := TStringList.Create; 898 943 899 944 finalization 945 //kt causing crash --> Reg.WriteString('footer',StoredIEFooters); 946 //RestoreIEPrinting; 900 947 PrinterEvents.Free; 901 948 SubsFoundList.Free;
Note:
See TracChangeset
for help on using the changeset viewer.