Solved

Want to write greek summation character "S"

Posted on 2013-11-21
17
346 Views
Last Modified: 2013-12-01
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
0
Comment
Question by:shawn857
  • 8
  • 7
  • 2
17 Comments
 

Author Comment

by:shawn857
ID: 39667182
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39667488
Hope you understand what I mean!

Not really, do you still have a problem?
0
 

Author Comment

by:shawn857
ID: 39667514
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39667562
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
 
LVL 1

Expert Comment

by:livestuff
ID: 39667582
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
 

Author Comment

by:shawn857
ID: 39667593
Thanks Livestuff... how do I do all this? I've never dealt in different character sets in Delphi.

Thanks
   Shawn
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 39667594
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
 

Author Comment

by:shawn857
ID: 39667613
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 19

Expert Comment

by:MerijnB
ID: 39667636
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
 

Author Comment

by:shawn857
ID: 39667679
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
 
LVL 1

Expert Comment

by:livestuff
ID: 39667691
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39668169
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
 

Author Comment

by:shawn857
ID: 39669747
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39670203
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
 

Author Comment

by:shawn857
ID: 39684494
Merjin. do you mean update my version of Delphi, or update my version of Quickreports?

Thanks
   Shawn
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 39684758
Shawn, probably both.
0
 

Author Closing Comment

by:shawn857
ID: 39688723
Thank you Merjin

Cheers
    Shawn
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now