Want to write greek summation character "S"

Hi, I simply want to write to a text fie (using writeln) the Greek character for summation - S. But when I'm coding and I try to paste that character in my writeln statement, it just shows as the letter "S". How can I write this character out to my text file?

Thanks!
    Shawn

P.S: I'm using Delphi 7
shawn857Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MerijnBConnect With a Mentor Sr. Software EngineerCommented:
You can cheat a little bit by manually writing a BOM to your file, to make it unicode. This example works here, but you have to keep in mind that this is now a UTF-8 file.

const UTF8BOM = #$EF#$BB#$BF;
      UTF8SIGMA = #$CE#$A3;
var f: TextFile;
begin
 AssignFile(f, 'd:\test.dat');
 Rewrite(f);

 // first manually add a BOM so the file is recognized as UTF-8
 Write(f, UTF8BOM);

 // now write the sigma
 WriteLn(f, 'sigma: ' + UTF8SIGMA);
 CloseFile(f);
end;

Open in new window

0
 
shawn857Author Commented:
Whoops, now that I read this post, it's changed the greek summation character to the letter "S" all the way through. When I typed my original post in, I had pasted in that greek character... guess it changed it. Hope you understand what I mean!

Thanks
   Shawn
0
 
MerijnBSr. Software EngineerCommented:
Hope you understand what I mean!

Not really, do you still have a problem?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
shawn857Author Commented:
Yes, I simply want to be able to output the greek character for summation (see http://fsymbols.com/signs/sigma/) to a text file using a writeln statement. Any ideas? is there some escape code or ordinal code that will allow me to write out this special character?

Thanks
   Shawn
0
 
MerijnBSr. Software EngineerCommented:
WriteLn in Delphi 7 doesn't support unicode, so outcome will depend on the codepage used locally (so not something you can trust on it will work always / everywhere).

Why do you need to use WriteLn?
0
 
livestuffCommented:
In Delphi 7, the VCL is still based on Ansi, not Unicode. You have to make sure the Sigma character is encoded in AnsiString
0
 
shawn857Author Commented:
Thanks Livestuff... how do I do all this? I've never dealt in different character sets in Delphi.

Thanks
   Shawn
0
 
shawn857Author Commented:
Thanks Merjin... what is a BOM, by the way? I'm a total newbie when it comes to this Unicode stuff. So will I still be able to write all my other regular text to my text file as normal? Or will this UTF format mess everything up? The file I'm trying to write is completely normal (ie. ascii) except for this one greek character I'd like to output.

Thanks
   Shawn
0
 
MerijnBSr. Software EngineerCommented:
In (very) short:

BOM stands for Byte Order Mark. Unicode comes in a few different flavors, of which UTF-8 looks the most like ansi. Each flavor has it's own BOM, such a BOM is placed as the very first bytes in a file. It's simply to tell whoever is viewing the file: this file is encoded as UTF-8.

You could get in trouble if you currently write characters from the upper half of the ascii table ( Chr(128) and up), these are the chars like: æ, ò and Û. It's probably best to try this and see if everything looks ok.

Who or what is reading the file, should you be able to read the file using Delphi as well?
0
 
shawn857Author Commented:
Oh okay. Are these BOM bytes visible in my output file? I'm simply creating a very plain vanilla report file that looks something like this:


Subtotal: <CallerID_1>             FILE 1                    FILE 2  
----------------------             ------                    ------            
   
1302873831                                                   Count : 2
                                                                       Sum   : 9.0000
     
1782513168                                                   Count : 2
                                                                       Sum   : 7.0000
     
... and instead of the word "Sum", I want to show the greek sigma character. (instead of "Count" I will show the "#" sign instead). Nothing complicated.
   No, I don't write any characters above Chr(128) - I only write out normal readable characters. Shouldn't be any problem there.
   It's simply a report file that will be eyeballed by the end-user, and maybe printed out. That brings up a question - will the sigma character print okay?
   Also, the file will not be read as input.

Thanks!
    Shawn
0
 
livestuffCommented:
In Delphi 7, Unicode characters can become a mess. If I were you, I would save yourself time and hassle and leave sum just as it is "Sum"  or better yet "Total"
0
 
MerijnBSr. Software EngineerCommented:
Hi Shawn,

The answer to both your questions depends on what the end user is using to view and print the report. If the end user is using an editor which properly supports unicode (which is almost every somewhat recent edigor) you won't see the bom and printing should be fine. Try opening the file yourself in notepad.exe and you'll see that works fine.

Though I agree with livestuff that this could get messy in Delphi 7,since you only write the file here and that's it, I don't think you'll have any problems.
0
 
shawn857Author Commented:
Well, ultimately I do plan to have my app create my report internally in QuickReport and allow the user to choose his form of output - ie. PDF, HTML, CSV, XL, ASCII, etc. So it might start getting a little messy then... that greek character might screw everything up for those different output types eh? Maybe I better not open this can of worms at all, and just stick with the word "Sum" in my report instead of the greek character.

Shawn
0
 
MerijnBSr. Software EngineerCommented:
That will depend on whether quickreport supports unicode (widestring) or not.

If you update your Delphi version there won't be an issue at all.

You can keep it in now, and switch back to "sum" later if you run into trouble I'd say :)
0
 
shawn857Author Commented:
Merjin. do you mean update my version of Delphi, or update my version of Quickreports?

Thanks
   Shawn
0
 
MerijnBSr. Software EngineerCommented:
Shawn, probably both.
0
 
shawn857Author Commented:
Thank you Merjin

Cheers
    Shawn
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.