Delphi - ANSI - UNICODE

Logic

Početnik
Poruka
24
Zanima me da li neko od ljudi koji posecuju ovaj Forum, moze da mi pomogne oko sledeceg.
Da li Vam je poznato kako u Delphi-ju mogu da prebacim snimanje nekog File-a iz (podrazumevanog) ANSI u UNICODE? Tj. program kreira neki .txt file, a zatim ga snima. Zanima me kako mogu da podrazumevani encoding ANSI prebacim u UNICODE. Ideja je da se isti snima direktno, a ne klikom na Save As.
Hvala.
 
kako mislis automatski?
automatski bi bilo da sadrzaj memo-a ili slicnog sacuvas direktno, a pesacki sa Rewrite i slicno. Pogledaj na delphi3000.com i torry.net, siguran sam da ima tamo nesto za to.
 
Pazi, nije problem da ja to prebacim u neki File.... to je OK. Problem nastaje kada se File snimi. Recimo, iz neke baze (SQL) povukao sam podatke, te podatke prebacio u neki Memo (nije komponenta) ili bilo sta drugo, odakle sam napunio neki .txt Problem je u tome sto u zavrsnoj liniji koda stavljam SaveFile... e kada mu to zadam on ga snimi u ANSI formatu.
 
u delphiju su (kolko ja znam) stringovi ansi, a ne unicode, sto znaci da je i memo takav - za karakter se odvaja 8 bitova a ne 16 sto ne omogucava unicode text. stvarno ne znam kako da ti pomognem, i ja sam jednom imao takvih problema...zar nema nista na onim sajtovima?
 
Pronasao sam.

To store all text displaying into the program code, it is necessary to convert other than ANSI character to their special code page, because you cannot place Unicode writing in program code. In DELPHI3000 is a good article describing how to do that (the article 3198 is from Daniel Wischnewski, “Converting Text for different Code Pages”). Place anywhere in your program a Button and turn him to NOT VISIBLE. This button is only for you. Behind the Button is the call:

procedure TForm1.Button1Click(Sender: TObject);
var
InList:WideString;
OutList:TStringList;
F: File of WideChar;
s:WideChar;
begin
//This part is only for developing to translate Chinese text to
//code page. The Button is normaly unvisible !!!!!
//working only until 2 GB Files (because of WideString Max)!!!
OutList:=TStringList.Create;
InList:='';
AssignFile(F,'Program Translation.txt');
Reset(F);
Read(F,S); //we do not need the unicode file mark
while not EOF(F) do begin
Read(F,S);
InList:=InList+s;
end;
CloseFile(F);
OutList.Text:=TransferUnicodeToCodePage(CODEPAGE_Chinese_PRC,InList);
OutList.SaveToFile('Program Translation CodePage.txt');
OutList.Free;
end;
 
E, bilo bi super da mi posaljes i to tvoje resenje... bas me zanima da li bih mogao da uradim to jaos na neki drugi nacin osim onog koji sam poslao (doduse ne u celini). Ako te zanima kompletno resenje, reci mi pa cu ti ostaviti na forumu.
Pozdrav.
 
function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
var
l: integer;
begin
if ws = ' then
Result := '
else
begin
l := WideCharToMultiByte(codePage,
WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
@ws[1], - 1, nil, 0, nil, nil);
SetLength(Result, l - 1);
if l > 1 then
WideCharToMultiByte(codePage,
WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
@ws[1], - 1, @Result[1], l - 1, nil, nil);
end;
end; { WideStringToString }

function StringToWideString(const s: AnsiString; codePage: Word): WideString;
var
l: integer;
begin
if s = ' then
Result := '
else
begin
l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), - 1, nil, 0);
SetLength(Result, l - 1);
if l > 1 then
MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]),
- 1, PWideChar(@Result[1]), l - 1);
end;
end; { StringToWideString }
 

Back
Top