Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2003, 12:18 PM
dbassett74 dbassett74 is offline
Senior Member
 
Join Date: Jun 2002
Posts: 395
Default Load file into string, then stringlist?

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
Reply With Quote
  #2  
Old 02-25-2003, 02:02 PM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Load file into string, then stringlist?

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;


Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #3  
Old 02-25-2003, 09:45 PM
DarkHorse DarkHorse is offline
Senior Member
 
Join Date: Dec 2000
Posts: 1,636
Default RE: Load file into string, then stringlist?

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.

Pls. accept if it helped.

Thanx
Tomy.
Reply With Quote
  #4  
Old 02-26-2003, 05:35 AM
dbassett74 dbassett74 is offline
Senior Member
 
Join Date: Jun 2002
Posts: 395
Default RE: Load file into string, then stringlist?

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..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.