tags:

views:

52

answers:

1

hi all

i am trying load file after it created from /stext command line but its not loading up

my code

ShellExecute(0, nil, PChar(path+'test.exe'), PChar('/stext "' + path + 'save.txt"'), nil, SW_HIDE);

after it created file i tried to load to memo1 from another button click

like

procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.LoadFromFile(path+'save.txt');
end;

but its loading some unknown 3 characters

ÿþ=

P.S : I opened manually it has real data of 30 lines :)

why its happening ?

and one more thing is after i executed my first command shellexecute how i know that the file creation is done to load to my memo in same function without using sleep function :S

thanks in advance

regards

A: 

Try and see if this works

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Lines.LoadFromFile(path+'save.txt', TEncoding.UTF8);
end;

because the first characters you posted I think are from the UTF8 encoding.

Also, to double check if it's the encoding. Try opening that file in notepad, and see if it's alright.

Aldo
not worked and yeah i opened with note pad it has real data of 30 lines .
steve0
how about TEncoding.Unicode ?
Aldo
no luck still :(
steve0
I don't know... could you provide the method which saves the file in the test.exe file, or put the 'save.txt' file into a zip and upload it somewhere so we can detect it's encoding (which seems to be the problem)
Aldo
i dont think its encoing problem because file has so many characters but it displaying only 3 .
steve0
What I'm saying is that here might be some file header, where the fourth byte is a NULL and that's why your .LoadFromFile only loads the 3first chars
Aldo
oh ic thanks for info sir anyway here u go one small file that generated http://www.xup.in/dl,12342219/save.rar/
steve0
Ok, so I downloaded your file, and here's some intresting stuff.First of all, the .LoadFromFile with a single parameter (the filename) loads the file alright. Second, the file headers are $FF $FE which is an UTF-16 (TEncoding.Unicode) (http://en.wikipedia.org/wiki/Byte_order_mark)So I guess, your problem relies elsewhere, since you know, 'It works on MY machine', I'm also assuming you use Delphi 2009 or 2010
Aldo
thanks for solution sir .i tested on delphi 2k9 and it worked . is there any solution that i can load that type of file in delphi 7 too ?
steve0
Aldo
thanks bro ,btw what about other question , how i know that it completed in creating a file .
steve0