![]() |
|
#1
|
|||
|
|||
|
I need to be able to do the following and I can't quite get it to work:
1) Load an encrypted text file into a string. 2) Manipulate the string (decrypt). 3) Move that string into a stringlist. 4) Access the values within the stringlist via the TStringList.Value[] function. I don't need help on item number 2, just 1 and 3,4. I tried loading the file into a stringstream, but when I copy that stream to the stringlist, it gets copied as a single string, but remember, I need it to act as if I were loading the file directly into the stringlist via the LoadFromFile function so it takes into account line breaks. Going from a stringstream seems to mess this up. Any help would be appreciated.. By the way, this all has to take place in memory, I do not want to create any temp files. Thanks, Dan |
|
#2
|
|||
|
|||
|
Something to get you started...
procedure TForm1.Button1Click(Sender: TObject); var fs: TFileStream; sl: TStringList; str: string; begin fs := TFileStream.Create('encrypt.txt', fmOpenRead); try // set the length of the string so it can hold the whole file SetLength(str, fs.Size); // read the while file into the string fs.Read(str[1], fs.Size); // decrypt str ????? you do this bit sl := TStringList.Create; try // assign the decrypted string to the string list sl.Text := str; // access the values by name label1.Caption := sl.Values['Value1']; finally sl.Free; end; finally fs.Free; end; end; Simon SadMan Software http://www.simes.clara.co.uk |
|
#3
|
|||
|
|||
|
Hi,
What abt this way... Load the file into the stringlist first, then decrypt it and put it back to the stringlist itself. procedure TForm1.BitBtn1Click(Sender: TObject); var MyList: TStringList; i: Integer; begin MyList := TStringList.Create; MyList.LoadFromFile('C:\Encrypted.txt'); for i := 0 to MyList.Count - 1 do MyList.Strings[i] := Decrypt(MyList.Strings[i]); // or even this way MyList.Text := Decrypt(MyList.Text); end; good luck. Thanx Tomy. |
|
#4
|
|||
|
|||
|
Thanks, but it won't work because the whole file is encrypted, not just the individual lines. So when it is first brought into the stringlist, it brings it in as a single string because it cannot detect any carriage returns because they are all encrypted.
Isn't there a way for me to first pull it into a sting, decrypt it, and then put it into a stringlist so it detects the carriage returns and breaks out each line into a string, all in memory? I think I might have received another reply on this so I'll take a look.. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|