Mega Code Archive

 
Categories / Delphi / Examples
 

Textconvert

TEXT COVERSION CODING NOTES- (mostly SUPERCEDED) CAPS PROGRAM NOTES/COMMENTS See ChgCase directory for GOOD coding of text conversion techniques... {by default in Delphi (unless you change a compiler switch) the size of a string is limited by the memory available (or, around 2Gb) so one might be tempted to take advantage of this: one might use the AnsiUpperCase function to work on a string, so copying data from the buffer all in in one go into the string, and after converting it, then appending each new buffer/string-full of data to another string. One might THEN make use of a RichEdit component's SaveToFile method, by copying the appended string to the RichEdit and saving that to file, keeping the RichEdit hidden all the time. HOWEVER, in practise (because it's not good to ASSUME that there's lots of memory available) a big file will end up being truncated using this method: tempStringOne := buffer^; tempStringOne := AnsiUpperCase(tempStringOne); tempStringTwo := tempStringTwo + tempStringOne; {A small program to illustrate techniques for reading a potentially LARGE file, and then CONVERTING ALL LOWERCASE CHARACTERS IN THAT FILE TO UPPERCASE, and saving it back to disc again. Note that the block-reading routines and the techniques used for dealing with conversion are BLOODY FAST...} {IMPORTANT NOTE: for future reference RUNNING THIS KIND OF PROGRAM (WITH EXTENSIVE USE OF BUFFERS/SAVING BUFFERS TO FILE ETC) FORM THE DEPHI IDE MAY NOT ALWAYS PRODUCE THE RESULTS IT SHOULD. Sometimes, for example, one may find that the files one writes to won't load into WordPad, for example, so TEST PROGRAMS LIKE THIS BY COMPILING, AND THEN EXITING THE IDE, to run the .exe file from Explorer or whatever... see also EXTRA NOTES at the end...} {EXTRA NOTES. the output file is opened in such a way that if when first opened there was something in the file, that's erased and we've got a clean slate to work with. But each time this CapitaliseBuffer procedure is called, we append the current buffer to what might have been written to the file by previous calls note: this prog is a 'quick-test' prog -no checking of I/OResult or input/output exceptions... BlockWrite is nice and fast, better than Write etc... note that we use 'bytesRead' and not maxBufferSize if LastRead is True because the last buffer read is almost certain to be smaller than maxBufferSize, OK... note that we don't need to Seek to the end of previous data in the file because 'The current file position is advanced by Result records as an effect of the BlockWrite'.... if reading and writing the LAST buffer (almost certainly less than maxBufferSize size, then include code like this: if (lastRead = False) then BlockWrite(destFile, Buffer^, maxBufferSize, NumWritten); if (lastRead = True) then BlockWrite(destFile, Buffer^, bytesRead, NumWritten);}